Tag Info

New answers tagged

2

Yuch, too much maintenance and too much individual stuff. I'd recommend putting most of the effort into having appropriately scoped names that are appropriate for the platform so you can just have all of them all of the time. PYTHONPATH is a good example... you're unlikely to want to repurpose it for a Ruby project... You can group and mark the group with ...


0

Zsh needs to know how wide the prompt is in order to get the cursor position right. If it assumes an incorrect value for the width of the prompt, it will write text at the wrong place when redrawing the command line. That's what's happening after zsh moves to the next line to display possible completions: it redraws the command to be completed at the ...


1

You've completely banjanxed zsh's idea of what's been printed and what it has to erase/rewrite as it displays menu completion and lets you edit the command line. This is because you've overcomplexified that prompt. Don't use printf to just put a string literal inside a word. Don't use hardwired CSI control sequences to change colour. As I said at ...


23

Your confusion stems from the fact that many popular languages (especially C-based ones) stop evaluating && sequences when 0 is encountered, because 0 is considered false and everything else is true. In Bash, however, that's not the case. By convention, in POSIX systems (and all other Unix-like systems), return code 0 is considered SUCCESS (there was ...


4

Here, also using zsh, I have echo hai && echo bye hai bye And similarly echo hai && echo %? hai 0 Are you sure that you are seeing hai and bye on the same line with exactly the commands you have provided here? In direct answer to your question, an exit status of zero is success, so the second statement is executed. (This allows ...


8

The return value from commands are different from typical boolan values. 0 is success when executing a command, anything else is failure. && expects 0 to me success here for that reason.


0

You can source any file you like, it doesn't have to be .zshrc. You could make an env-setup script for each different project, and keep it in the project directory. If you want to be able to start new shells and have them load the env settings, you have a couple options: Always start your shells in the project directory, and have your .zshrc [[ -e ...


0

The problem lies with the zstyle for matcher-list. If you add the following to your .zshrc, it will fix it: zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'e:|[._-]=* e:|=*' 'l:|=* e:|=*' The e: (instead of the default r:) force the match to the end of the string. The details for the options can be found in the ZSH: Completion Matching ...


3

According to the zsh user guide, aliases should be defined in ~/.zshrc: You may be able to think of some aliases you want to define in your startup files; .zshrc is probably the right place. It also has a tip for keeping your ~/.zshrc clean: I only tend to use aliases in interactive shells, so I define them from .zshrc, but you may want to use ...


1

Place your environment variables in your ~/.zshrc file, they will get sourced automatically on each zsh session.


3

In most cases, that would be the redirection operator (<): $ tr 'a' 'b' /path/to/file ## fails because `tr` works on streams tr: extra operand ‘file’ Try 'tr --help' for more information. $ tr 'a' 'b' < /path/to/file ## works because the file's contents are passed to tr Both command substitution and the redirection operator are defined by POSIX ...


0

I suggest an approach that is halfway between glenn's two suggestions: use a (simple, scalar) variable, but break its definition into multiple lines: myword="super" myword="${myword}cali" myword="${myword}fragil" myword="${myword}istic" myword="${myword}expi" myword="${myword}ali" myword="${myword}docious"


1

Well, you could simplify it slightly to: $ [ -f /dev/null ] || sed 's/a/A/g' <(echo "thisis""avery"\ "long""string"\ "Ihave""separated"\ "into""smaller"\ "substrings") thisisAverylongstringIhAvesepArAtedintosmAllersubstrings The important point is to not have any extra whitespace in the input string, so no spaces around the \. Glenn's suggestion to ...


4

Using line continuations like that adds spaces into your string: the sequence backslash-newline-whitespace will be replaced by a single space. Just using a variables will go a long way towards improved readability: url="reallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallylongstring" { somecheck || somecomand ...


3

do is a reserved word in the shell. It's part of the syntax of while and for loops. When you define it as an alias, the alias takes precedence over the reserved word. So the shell sees, after alias expansion: if [ -d "$_dir/pre" ]; then for config in "$_dir"/pre/**/*(N-.); ssh -L xxxx:127.0.0.1:xxxx -N -f -l user -p xxxx xx.xx.xxx.xxx . $config done ...


1

!! is history expansion. The first ! starts a history expansion; !! has the event designator meaning the previous command. You can access the command history via the fc and history builtins and via the history variable. Since --vimgrep only makes sense with ag, your alias would be more useful if it applied to the last ag command. You can locate the ...


0

I have a piece of code updating the prompt asynchronously, but it has some issues: occasionally an error message is printed, saying it can't find the background job. sometimes after executing a command, the last line of the output is overwritten (so you can't see it), or the prompt isn't re-printed. The code: # git branch in prompt {{{3 ...


0

I find that while screen doesn't interpret named characters such as \n, it does take care of octal escapes. So instead of stuff 'echo "The array has of elements."\n', you could use: stuff 'echo "The array has of elements."'\012


3

From the bash documentation: Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows: \a alert (bell) (...) \nnn the eight-bit character whose value is the octal ...


0

Start by taking a look at your environment and finding the right option printenv|grep SSH SSH_CLIENT=192.168.1.xxx SSH_CONNECTION=192.168.1.xxx SSH_TTY=/dev/ttys021 You could hook into many of these environment variables to trigger specific actions based on their presence.


1

Why not just use a second shell to check for details? I use screen for that, or just switch to a second desktop where I (usually) also have an open shell. This way, I only spend one extra shortcut to switch to the backup shell and one more to switch back. Of course, this technique won't work in the last case you describe, because my second shell won't have ...


2

For zsh there are three widgets, which can bound to that effect: push-input, push-line and push-line-or-edit (see man 1 zshzle for more information). On the top-level prompt (PS1) they behave the same: The current buffer is pushed onto the buffer stack and then cleared. On the next promp (or when calling the widget get-line) the buffer will be popped of the ...


7

The purpose of ${1+"$@"} for portability. POSIX defined $@ would expand to nothing if there're no positional arguments. But original Bourne shell (or /bin/sh in Solaris 10 and before) would expand it to "". Using ${1+"$@"} is a work around for this, since when "$@" only expanded if $1 was set. Unfortunately, this construct doesn't work in zsh 3.x and pre ...



Top 50 recent answers are included