Tag Info

New answers tagged

2

zsh -o SOURCE_TRACE and some more words to get to at least 30 characters.


0

I think you do not need widget for that: bindkey -s '\eb' '/path/to/script.sh\n' From zsh docs: As well as ZLE commands, key sequences can be bound to other strings, by using ‘bindkey -s’.


0

First what comes to my mind is to get PID after process creation, use zstat tool (see man zshmodules) to get get process timestamp, e.g. zstat '+mtime' /proc/PID, and after desired amount of time check if timestamp for given /proc/PID has no changed - if yes kill the job.


0

With zsh, if you're using the completion system, you can do: zstyle ':completion:*' matcher-list '' 'r:|?=**' Which seems to work. I won't pretend I understand fully how that works, you can read: info -f zsh --index-search=matcher-list And also follow the link there to: info zsh 'Completion Matching Control' for details.


0

I'm on fedora now yet I suggest you to read Archlinux's wiki carefully, all of it: Home and End keys not working. What I did to fix it: Press Ctrl-V Home, the escaped sequence for Home key is printed. It is not \e[4~ and \e[1~ as I expected to be by looking at /etc/inputrc. It was [H and [F Extract the terminal info infocmp $TERM >terminfo.src Open ...


0

Thanks to don_crissti for answering this for me. The correct if block is below. if [[ ! -a ~/.zkbd/$TERM-${${DISPLAY:t}:-$VENDOR-$OSTYPE} ]]; then zkbd fi


0

Using the c-shell (tcsh to be exact) from the command line: mymachine % alias showme "echo here it is" mymachine % showme here it is or put it in the .cshrc file then source the file: mymachine % so # so is an alias for source ~/.cshrc mymachine % showme here it is mymachine % ssh garnet showme here it is


0

Just a note: you can make it shorter with: for e ($a) b+=("$(my_cmd "$e")") Note that $a loops over the non-empty elements. To loop over all the elements, it's "$a[@]".


0

If you know in advance what the command is doing with array elements then you can use parameter expansion flags (see man zshexpn) to instruct zsh how to adapt command output to array. Example Let's say an array a contains the names of files, and each file contains only one line of text: $ a=(foo 'bar baz') $ cat foo A $ cat 'bar baz' B C Now let's ...


0

You could do: eval "b=(" '"$(cmd "$a['{1..$#a}']")"' ")" But that's not very legible.


1

You can always declare a function for that: map() { local arrayname="$1" cmd="$2" i shift 2 eval "$arrayname=()" for i do eval "$arrayname+=(\"\$($cmd)\")" done } And use as: $ a=(a '' bcd) $ map b 'wc -c <<< "$i"' "$a[@]" $ echo $b 2 1 4


7

You can not do it. Because aliases were expanded only after history expansion and entire line was read in one go, so when foo was executed, the alias expansion process was gone, it's too late for the shell to recognize new alias. The best way you can do is defining alias in .zshrc or using function like jimmij's answer or using eval: alias foo=ls; eval ...


7

This is very well known problem which is even described in zsh manual under chapter ALIASING (see man zshmisc). The recomended way of dealing with it is to use function instead of alias: foo() { ls; } ; foo or even better in case of ls: foo() { ls -- "${@:-.}"; } ; foo ps. semicolon at the end of the function definition (list) and spaces are not ...


7

When you press Ctrl+Z in a terminal, this causes the foreground process group to receive the signal SIGTSTP (assuming the terminal is in cooked mode and the default key bindings are in place). If the process hasn't set a signal handler for SIGTSTP, this causes the process to be suspended (and even if the process has set a signal handler, it usually only does ...


6

Having a global keybind to disown the foreground process is impossible: Keystrokes are received by the foreground process, not by the shell. You need to first suspend it with Ctrl+z if you want to disown it. However, turns out there's a zsh option to speed up disowning then continuing: With setopt AUTO_CONTINUE, disown will automatically also send SIGCONT. ...


0

Yet another way to achieve it is print *(/) or echo *(/) Update1 A bit more correct version (as noted by @Stéphane Chazelas) would be print -rl -- *(/) or echo -E - *(/) respectively to take care about spaces, escape sequences and leading hyphens inside filenames. Update2 Yet even more correct version is print -rN which additionally takes ...


3

For a Standard Shell (bash) (POSIX.1) Start it with &, make it read from something other then the default stdin (==/dev/tty == /dev/stdin == /dev/fd/0) + make it write to something other than the default stdout (==/dev/tty == /dev/stdin == /dev/fd/1) (same for stderr) and make sure the job isn't or doesn't get suspended(=stopped). If it must get stopped ...


1

You may find useful (though it doesn't use disown, nohup or &) trying screen or tmux. Both tools allow you to run multiple terminals and detach from them without stopping what its happening in each one. I find tmux more convenient. Using tmux You can name sessions, tmux new-session -s ${SESSION_NAME} start one without attaching to it, tmux ...


0

You could start your program as a batch job, e.g. using a here document : batch << EOJ ./yourprogram some $ARGUMENTS EOJ If the program has been already started interactively, I don't see any general failproof solution; e.g. because that program might later start using system(3) (e.g. system("$EDITOR /tmp/somefile.txt");....) some X11 client ...


1

Please, on behalf of future maintenance programmers and sysadmins - DON'T use a regex to parse XML. XML is a structured data type, and it is NOT well suited for regex parsing - you can 'fake it' by pretending it's plain text, but there's a bunch of semantically identical things in XML that don't parse the same. You can embed linefeeds, and have unary tags ...


1

I believe you cannot always get the current shell's name, and I think you should be aware of the limitations of what is possible. On Linux distributions, most users would have bash as their login & interactive shell (since bash is the default shell on most distros). Some users would set their shell to zsh, csh (and variants) or to fish. (As other ...


2

So I am still trying to flesh this out, but I think I have an idea that will work. As you have noticed what you are trying to do is if not impossible exceedingly difficult to do in the all shells (each variant you add to the polyglot increases the complexity at a greater than linear rate). you could probably do it if you split into borne (sh, ash, dash, ...


1

try somethings like this shell_bin=$(ps h -p $$ -o args='' | cut -f1 -d' ') echo $shell_bin


-1

use below at own risk disclaimer tmp=`head -n 1 $0` SHELL_BIN=`readlink -f ${tmp#*!}` SHELL=${SHELL_BIN##*/}


1

You can batch process your files with mogrify and convert from one format to another using the -path option (as of imagemagick v6.2.0) to specify a different directory in which to output the processed images: mogrify -path /path/to/dest_filename -format ext2 /path/to/source_filename/*.ext1 so e.g. mogrify -path /home/myjpgs -format jpg ...


1

** doesn't follow symlinks since bash-4.3. See CHANGES between bash-4.3-release and bash-4.3-rc2: globstar (**) no longer traverses symbolic links that resolve to directories. This eliminates some duplicate entries.


0

I added those keys : bindkey -M vicmd '?' history-incremental-search-backward bindkey -M vicmd '/' history-incremental-search-forward I do as CTRL+R in emacs mode and I prefer


-2

Here is one: ls | cut -d '_' -f1,2


2

The equivalent of the * regexp operator in zsh -o extendedglob is # (## for +). And you can also use ksh-style globbing with the kshglob option. So either: setopt extendedglob # best in ~/.zshrc ls -d filename.mainsuff_[[:alnum:]]# Or: setopt kshglob ls -d filename.mainsuff_*([[:alnum:]])(-) (The (-) part is to prevent ([[:alnum:]]) from being taken as ...


0

I had been wanting to integrate Zsh's cut buffer with the X clipboard. I tried the aforementioned http://stchaz.free.fr/mouse.zsh but I found I disliked having all my Zsh operations populate the clipboard. For instance, sometimes I would copy something in a browser, and then go to a shell and edit the command line and then paste. But often editing the ...



Top 50 recent answers are included