Hacker News new | ask | show | jobs
by junkblocker 1648 days ago
Since I was trying out nushell, I came across Starthip which supports nushell! I noticed that prompt managers which run non-shell binaries may be unable to support things like showing the tty since I assume they are execing any external tools (/usr/bin/tty) in a non-tty environment. But still very cool to have the same prompt run unmodified in zsh, bash, nushell etc. The git VCS performance in it is pretty good too even in large monorepos.
1 comments

On linux (and I think even osx), even when stdin, stdout, and stderr are redirected, you can always get at the current session's tty via "/dev/tty" unless the executing program spawns a new session which would be very unlikely in this case. This is why things like sudo can defeat pipes and prompt you.
Oh, you are right! This works by looking at /proc/$ppid/fd/1

    format = """$all\
    ${custom.tty}"""

    [custom.tty]
    description = "tty"
    when = 'true'
    command = """
    tpid=$(ps -o pid= -p "$(($(ps -o sid= -p "$$")))")
    tpid=$(( tpid + 0 ))
    readlink /proc/$tpid/fd/1 | sed -e 's|/dev/||'
    """
    format = ' [$output]($style)'
    shell = ["bash", "--noprofile", "--norc"]
    style = 'blue'