I’m sure some of you have absolute monstrosities of sigils (I know I do, in my .zshrc alone). Post them without context, and try and guess what other users’s lines are. If you want to provide context or guess, use the markdown editor to spoiler-tag your guesses and explanations!

  • @kartoffelsaft
    link
    English
    2
    edit-2
    1 year ago

    Moving the cursor will confuse bash and you can get the same effect by just omitting the last \n.

    When I was testing it I did not get the same effect. Instead it would only put the background behind what I had typed and not the whole line. Doing it now it seems to be working with the omission. I would assume it’s a terminal emulator bug because I believe I have changed emulators since I wrote it. I’ve now removed it, thanks for fixing a bug.

    Avoid doing external commands in subshells when there’s a perfectly good prompt-expansion string that works.

    I wanted my home directory to not get shortened to ~, and if there is some way to do that with \w it isn’t easy to find out how.

    Also, what’s the reasoning for avoiding it (besides it being idiomatic)? I’m sure there is one, but I don’t think I’ve run into it yet.

    You seem to be generating several unnecessary blank lines

    I just like the look of it, and I have the screen space to do it.

    • @o11c
      link
      English
      31 year ago

      Two of the most expensive things a shell does are call fork and call execve for an external program. pwd is a builtin (at least for bash) but the former still applies. $PWD exists even if you don’t want that shortening; just like your backticks be sure to quote it once so it doesn’t get expanded when assigning to PS1.

      In general, for most things you might want to do, you can arrange for variables to be set ahead of time and simply expanded at use time, rather than recalculating them every time. For example, you can hook cd/pushd/popd to get an actually-fast git prompt. Rather than var=$(some_function) you should have some_function output directly to a variable (possibly hard-coded - REPLY is semi-common; you can move the value later); printf -v is often useful. Indirection should almost always be avoided (unless you do the indirect-unset bash-specific hack or don’t have any locals) due to shadowing problems (you have to hard-code variable name assumptions anyway so you might as well be explicit).