Tag Info

Hot answers tagged

5

setopt extendedglob cat <->.csv > all.csv Where <-> matches any positive integer decimal number, will concatenate all those (in lexical order, which for 0 padded numbers is the same as numerical order) into all.csv. That will double the space on disk though. If you don't intend to keep the original files, you could do: for i in ...


5

Well, you could always just do ~ for i (drop create migrate) echo bundle exec rake db:$i bundle exec rake db:drop bundle exec rake db:create bundle exec rake db:migrate Or ~ echo bundle exec rake db:{drop,create,migrate} bundle exec rake db:drop db:create db:migrate


4

You must use "${(@k)array}", "${(k)array}" only expands to the non-empty keys: typeset -A array array=(k1 v1 k2 v2 k3 v3) for k in "${(@k)array}"; do printf "%s -> %s\n" "$k" "$array[$k]" done Then: $ zsh test.zsh k1 -> v1 k2 -> v2 k3 -> v3 You can also replace for loop with key, value expansion: printf '%s -> %s\n' "${(@kv)array}" ...


4

zsh has different parameter substitution than Bash, which is documented in man zshexpn. It supports a variety of modifiers to expansion behaviour, which are put in parentheses before the variable name: ${(X)name}. The modifier to include array keys (including for associative arrays) is k: ${(k)array} expands to the list of keys in the array, except that if a ...


3

You only need the grml-zsh-config package like: pacman -S grml-zsh-config ...and maybe to set your default shell to zsh like: chsh -s /usr/bin/zsh [username] You might also want to check what else you can get like: pacman -Ss zsh


3

For it show as those 3 lines, you'd need: $ print -rl 'bundle exec rake db:'{drop,create,migrate} bundle exec rake db:drop bundle exec rake db:create bundle exec rake db:migrate x{a,b}y creates 2 arguments where {a,b} is replaced with a in the first and b in the second. If you wanted the above to be executed, you could pipe it to sh (or zsh though ...


3

The problem is that curl expects some normal terminal settings and zle doesn't expect you change the terminal settings. So you can write it instead: _check-gmail() { zle -I ( s=$(stty -g) # safe zle's terminal setting stty sane # sane settings for curl curl -u username --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' ...


2

In zsh, history is an alias for fc -l 1, so when you do history -20 it get replaced by fc -l 1 -20 which just won't work, so instead use fc directly: ➜ ~ fc -l -20 10095 grep -R PAPER /usr/lib/locale/ 10096 man locale 10097 man 7 locale 10098 mc 10099 history 10100 history --help 10101 run-help history 10102 history 20 10103 history 1 20 10104 ...


2

You can disable the PATTERN(QUALIFIERS) syntax by unsetting the bare_glob_qual option: setopt no_bare_glob_qual If the option extended_glob is set (and you should set it, the only reason not to set it is for backward compatibility with rare scripts that use unusual syntax), then there is another syntax for glob qualifiers: PATTERN(#qQUALIFIERS). So you ...


2

Set the SH_GLOB option. setopt sh_glob From man zshoptions: SH_GLOB Disables the special meaning of (',|', `)' and '<' for globbing the result of parameter and command substitutions, and in some other places where the shell accepts patterns. If SH_GLOB is set but KSH_GLOB is not, the ...


2

AFAIK, ${!...} doesn't exist. I suppose you want: ${(k)array[@]}, or simply ${(k)array}. For more information, see the zshexpn(1) man page, which says for the k expansion flag: "If name refers to an associative array, substitute the keys (element names) rather than the values of the elements."


2

Corrections apply automatically because they are first on a group list, before original. You can change that with zstyle ':completion:*' group-order original corrections And the result is Credit for the final solution goes to Stéphane Chazelas.


2

If you use redirection, that will either append or overwrite contents to one file. If you want to append to one file, use: cat file.csv file2.csv file3.csv >> all.csv This next command will overwrite to all.csv: cat file.csv file2.csv file3.csv > all.csv But say you want to move all CSV files to one csv in a given directory (to append to): cat ...


2

You may already know zsh-history-substring-search. It does not do preview you have seen, as far as I can tell, but otherwise it seems to be very similar. If you do not know it, it's worth trying. zsh-history-substring-search is closely based in the history search of the fish shell. fish has some pretty advanced features in terms of interaction, certainly ...


2

No, it's expanded to: bundle exec rake db:drop db:create db:migrate From zsh documentation, braces expansion section: A string of the form ‘foo{xx,yy,zz}bar’ is expanded to the individual words ‘fooxxbar’, ‘fooyybar’ and ‘foozzbar’. Left-to-right order is preserved. This construct may be nested. Commas may be quoted in order to include them ...


1

Use this: "${index}_${lumarr[lum]}" Generally: Interpolate all variables using ${...} notation. Unless you expressly want to use word-splitting, always enclose variable interpolations in double-quoted strings.


1

The top line of less output scrolls out on top because you print a line at the bottom, causing one line of scrolling. That's the \n in your prompt. How to avoid this, and still have two lines? You could write part of the prompt above the mormal command line, instead of using a two line prompt. In a sense, it would be one normal line, and one printed above ...


1

Answering the alternative part of your question, "...help me programm it with updating the list properly": You can directly use the functions that list completion items, update the list, or clear it; That's zle -R. To write out your own "unmanaged" text, there is zle -M. From pinfo zsh: zle -R [ -c ] [ DISPLAY-STRING ] [ STRING ... ] zle -M STRING [ ... ] ...


1

The array is defined in the shell interpreting your script, not the one running in your screen terminal window. To pass it to your screen window's zsh, try: screen -S "MYSCREEN" -p 0 -X stuff "$(typeset -p bkgarr)"$'\r' Note that it will send the newline characters as newline characters, not as carriage returns. That should be fine with zsh though (just ...


1

If you have many nested fancy aliases and you are not sure what zsh is actually doing with them and in which order options are passed to command then you can always start zsh with -x option. This will print commands and arguments as they are executed. Be aware however that this option is intended rather for debugging purpose so it prints a lot of useless ...


1

Note that Ctrl-Alt-E in bash does not only expand aliases. It also expands variables, command substitution (!), process substitution (!), arithmetic expand and removes quotes (it doesn't do filename generation (globbing) or tilde expansion). It doesn't always manage to expand aliases. So while it has its uses, it's important to realise its outcome ...


1

If you stuff a command line into a function definition and then print out the function, the aliases will be expanded. You'll also get normalized whitespace. % alias foo='bar -1' % alias bar='qux -2' % f () foo -3 % which f f () { qux -2 -1 -3 } To put all this into an interactive command, you can make a zle widget. You can define a function ...


1

Why do you want to combine all those files into one file? If you want to feed them to a program that wants stdin, you can do this: cat *.csv | prog or any of the other combination methods mentioned earlier. If the program expects a named file as input, do something like this: mkfifo p cat *.csv > p & prog p If you want one file because one file ...


1

The first thing to know, in zsh, history meaning fc -l. Then read man zshbuiltins, section about fc command: Select a range of commands from first to last from the history list. The arguments first and last may be specified as a number or as a string. A negative number is used as an offset to the current history event number. A string specifies ...


1

Provided you have execute permissions on the current directory - or on the directory from which you executed your shell script - if you want an absolute path to a directory all you need is cd. Step 10 of cd's spec If the -P option is in effect, the $PWD environment variable shall be set to the string that would be output by pwd -P. If there is ...



Only top voted, non community-wiki answers of a minimum length are eligible