Zsh is a shell with many advanced command-line and scripting features.
1
vote
0answers
27 views
Is there any plugin for zsh or bash that does heuristic filename completion?
Such as if
$ ls
program_v1.21.rb
program_v2.01.rb
program_v2.01_final.rb
so when I
$ echo progv2fin[TAB]
it completes to
$ echo program_v2.01_final.rb
Sure there must be something, but I ...
2
votes
4answers
29 views
zsh: map command to array
suppose you have an array a=(foo 'bar baz')
is there a more obvious way to apply a command/function to every array element and save the resulting strings into another array than this:
b=()
for e in ...
10
votes
3answers
227 views
Defining an alias and immediately use it
In zsh this works fine:
alias foo=ls
foo
But this does not:
alias foo=ls; foo
Pressing enter an extra time is not an issue when running interactively. But when running through ssh it suddenly ...
5
votes
2answers
105 views
In zsh, how can I more quickly disown the foreground process?
My method for disowning the foreground process takes too much effort.
Suppose I have a process in zsh's foreground. I want to disown it, so I can close the shell without the process being sent a ...
1
vote
0answers
20 views
Byobu - New window with same ssh session?
Is there a way to configure Byobu to use same ssh session in a new window. For e.g.
Open Byobu window
ssh into a remote host
Press 'F2' to open a new window. This opens the terminal with ...
2
votes
3answers
44 views
Preventing terminal disconnection from killing a running job in zsh [duplicate]
I went through the top answer to this question: Difference between nohup, disown and &, and I read specfically the following:
With disown the job is still connected to the terminal, so if the
...
1
vote
0answers
20 views
How to quickly search and navigate to the particular sub directory? [duplicate]
I often find myself in the situation where the directory structure is like:
a/b/c/d/f/g/...
and I am at a as pwd and wish to quickly navigate to f or g.
Is it possible to search and move to the ...
2
votes
4answers
163 views
How do I *reliably* and *simply* get the current shell interpreter name?
I'm looking for a simple and reliable way to get the name of the current shell from inside a script or a sourced file (not from the command line). I would have expected to just do $(basename ...
0
votes
0answers
7 views
How do I edit my directory colors in zsh so directories in a network share aren't so ugly? [duplicate]
The display colors of directories located on mounted network shares are horrid:
Local directories look much nicer:
As I understand it, these settings are set in these lines in .zshrc:
eval ...
1
vote
1answer
22 views
Backward and foreward search are inversed with vi mode in zsh
When I enter in vi mode with set -o vi, I enter in command mode, and I touch the key ? it produce a / and the inverse. Is it normal ? How to change this behavior?
1
vote
2answers
42 views
zsh - complex filename matching [closed]
I have trouble passing a list of file names to a program when utilizing globbing operators.
Essentially the problem is that I have files with multi-stage suffixes and I want to match only the master ...
1
vote
1answer
31 views
running screen in a shell can't find sessions but running screen during ssh login can
I am using the RemoteLoginAutoScreen script to start a screen session when I ssh into a host.
Differences from linked script: I am using zsh and the RemoteLoginAutoScreen uses bash
The problem that ...
1
vote
1answer
57 views
Expanding {a..d} to a b c d in zsh
In bash, {a..d} expands to a b c d. Currently this is not happening for me in zsh, and my googling has returned conflicting results.
Some results suggest that {a..d} should work ...
3
votes
1answer
56 views
How do you use variables with values containing spaces in a Z-shell (zsh) script command?
I have the following Z-shell script:
compiler=clang++
standard=-std=c++11
warnings="-Wall -Wextra -Wpedantic"
${compiler} ${warnings} ${standard} -o ${1} ${1}.cpp
This does not work as the ...
0
votes
1answer
20 views
Run .zshrc when passing command via -c
I have a script that runs a command via zsh -c. However, when zsh runs, it doesn't appear to load ~/.zshrc.
I understand a login shell flag exists, but even zsh -lc <command> doesn't seem to ...
3
votes
5answers
119 views
Efficient data extraction from multiple files to a single CSV file
I have a large collection of XML files with the same exact structure:
$ cat file_<ID>.xml
...
...
...
<double>1.2342</double>
<double>2.3456</double>
...
0
votes
1answer
21 views
Determine the tmux session a shell session belongs to?
tmux provides a number of commands in the shell such as rename-session which operate on the session that the invoking shell belongs to.
It also provides commands like list-clients which list out the ...
0
votes
2answers
29 views
“Quit and restart” control code?
I find myself frequently (after making some change to source) "Ctrl+C;↑ ing" to restart the program with changes.
Is there a way to do this more quickly, without wrapping the program in a loop ...
0
votes
1answer
18 views
Bind tmux prefix to section symbol §
I usually use the backtick key as my prefix, but this keyboard has the section/stanza symbol § where the backtick usually (at least, for me in the UK) is.
If I bind to this key, quoted or unquoted, ...
3
votes
1answer
40 views
How can I ignore / remove / exclude autocompletions in zsh?
I usually use rs+[tab] to get rsync but it's showing three options (on a new system):
➜ $ rs
rsh rsync rsyslogd
I seldom use rsh or rsyslogd - how can I prevent these from appearing ...
4
votes
1answer
96 views
What is this HOME command?
I'm able to run a command named "HOME" which appears to be equivalent to cd && echo "~".
But I can't figure out where it's defined:
$ pwd
/tmp
$ which HOME
HOME not found
$ type HOME
HOME not ...
0
votes
1answer
35 views
Can I conditionally turn certain oh-my-zsh plugins off?
This is more of a long shot, but here we go:
I use oh-my-zsh with the vcs-plugins git and svn on. I now started on a project where it would be most convenient to use sshfs. The problem that now comes ...
-1
votes
1answer
61 views
What does `zstyle` do?
zstyle seems like it's just a central place to store and retrieve data, like an alternative to export. Is that true, or is there more to it?
0
votes
1answer
29 views
Running a command on different shell
While reading the answers of question Can bash write to its own input stream?, I found following command runs on zsh but not on bash :
print -z echo mnciitbhu
1 . Is -z is an extension to print ...
1
vote
1answer
49 views
What is the difference between `autoload` and `autoload -U` in Zsh?
What is the difference between autoload -U and plain autoload?
For instance, here it is recommended to run:
autoload -U run-help
autoload run-help-git
autoload run-help-svn
autoload run-help-svk
...
1
vote
1answer
64 views
Configure tmux to use zsh
Right now I have my iTerm session configured to use zsh (/usr/local/bin/zsh), but I'm trying to configure tmux to use zsh as well, instead of /bin/bash/, which it's currently defaulting to. So far ...
1
vote
1answer
30 views
How to add a dir to fpath
I'm using zsh and prezto.
I've adding the following line at the end of my .zshrc
fpath=(/usr/local/share/zsh/site-functions $fpath)
But unfortunately, the functions defined in this folder seems ...
2
votes
1answer
52 views
Source .bashrc in zsh without printing any output
In the past, I've used bash consistently, because it's everywhere.
But recently I started to try zsh. I don't want to give up updating my .bashrc fil which is rsync'ed to all my servers .
So, in my ...
6
votes
1answer
46 views
zsh I/O redirection: redirecting and then piping; what is going on?
Can somebody explain what is going on in this command:
echo foo >&2 | grep foo
Zsh (5.0.2) prints foo twice. One seemingly to stdout and one to stderr, since running these commands:
{ echo ...
1
vote
1answer
77 views
zsh: Disable “file exists:” warning with redirection
How can I override the file exists: warning from zsh?
> echo > newfile.txt
> echo > newfile.txt
zsh: file exists: newfile.txt
In these cases I prefer my shell to not complain and ...
2
votes
2answers
41 views
How do I find the actual binary/script using 'which' in zsh? [duplicate]
In zsh, when I enter which git it shows:
git: aliased to noglob git
How do I find out which git binary it actually invokes? (eg: /usr/bin/git vs ~/bin/git). Basically I want to bypass the aliases ...
1
vote
1answer
45 views
Completions stopped working after upgrading zsh
Previously I have been using this handy script with oh-my-zsh to set the tab color whenever I ssh into a machine:
# iTerm2 window/tab color commands
# ...
1
vote
1answer
43 views
How to edit shell prompt to show time?
I would like to edit my shell prompt to display time. Am currently using zsh, though I would like the customize the shell prompt to show time.
I understand an echo $PS1 will give me the environment ...
3
votes
3answers
195 views
How to set HOSTNAME in zsh?
In bash, which sets $HOSTNAME for you, I was able to calculate the total length of prompt line simply by using something like:
PS1_length=$((${#USER}+${#HOSTNAME}+${#PWDNAME}+12+${#PS1_GIT}))
It was ...
2
votes
2answers
177 views
Zsh: export: not valid in this context
When running this script, I run into an error on this line (relevant snippet below):
...
_NEW_PATH=$("$_THIS_DIR/conda" ..activate "$@")
if (( $? == 0 )); then
export PATH=$_NEW_PATH
# If ...
0
votes
1answer
28 views
Should I move my custom commands from the end of ~/.profile to the end of ~/.zprofile when I install zsh and oh-my-zsh?
I am a new user of zsh and oh-my-zsh.
Before I installed zsh and oh-my-zsh I configured my ~/.profile to start some programs automatically. For example, my ~/.profile would start guake after a 4 ...
1
vote
3answers
129 views
String comparison in single brackets in zsh [duplicate]
Bash code to print all folders:
for f in ~/*;
do
if [ $f == '/home/sk/.' -o $f == '/home/sk/..' ]; then
true
else
echo "$f"
fi
done
It works on bash. When i ran the code on z ...
2
votes
3answers
48 views
reuse the last command output at the given index/line-num
ls
displays:
entry1
entry2
entry3
How can I reuse the above output (not all of the entries but the entry at a given line, say n) in the next shell command?
Something like:
vi $(!!)@3
Must ...
2
votes
3answers
59 views
Local `set -e` for functions
Is there such a feature or can it be emulated reasonably easily?
I want the same behavior except it should return where set -e would have caused a call to exit.
2
votes
1answer
92 views
Automatically colorize the output of tree
In plain zsh, tree is set similar to --color=auto by default. However, when I use Oh-My-Zsh, tree doesn't show colors. Since tree does not have a --color=auto option, how can I override the setting ...
1
vote
1answer
35 views
Setting backspace=2 in zsh with vi bindings
I just set my zsh to vi mode as I feel the word/WORD (w/b W/B) skip keybindings will help me work faster than plain ^a ^e in emacs binding mode. However, I'd like to set backspace=2 or set ...
2
votes
1answer
24 views
Overridable functions in Zsh
Consider the following two functions:
function slow_git_prompt_info() {
if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then
ref=$(command git symbolic-ref ...
0
votes
1answer
41 views
Read a line with default input in zsh
This function can be used to help user input a modification of some text.
function change { bash -c "read -ei \"$1\" temp && echo \$temp" }
What is idiomatic zsh way to do something ...
5
votes
2answers
88 views
Elegant way to prevent command substitution from removing trailing newline
I'm customizing my zsh PROMPT and calling a function that may or may not echo a string based on the state of an environment variable:
function my_info {
[[ -n "$ENV_VAR"]] && echo "Some ...
2
votes
2answers
67 views
Split shell horizontally to show ls -al and pwd
I use zsh as my default shell on OSX. I would like for my shell to always have a horizontal split showing pwd and ls of the current directory I'm in. How do I go about it ?
15
votes
1answer
677 views
What's the magic that allows me to tab-complete remote files as I type an scp command?
Presumably this is a feature provided by some plugin I have enabled in my oh-my-zsh setup (I have been using zsh for many years now).
I noticed ever since I added my public key to the server (now I ...
0
votes
1answer
51 views
Cannot get interface information using read
The following link has a script to get system information:
z3bra' blog
Specifically,
network() {
read lo int1 int2 <<< `ip link | sed -n 's/^[0-9]: \(.*\):.*$/\1/p'`
if iwconfig ...
2
votes
2answers
74 views
Reliably identifying the path to the directory containing the running script
There are plenty of answers in SO to address this question:
Can a Bash script tell what directory it's stored in?
Unix shell script to find out which directory the script resides?
And there are a ...
0
votes
1answer
36 views
A generic cron wrapper that records all output
I am hoping to write a cron wrapper that records all output in a folder $CRON_LOG_DIR.
It would be used as, e.g., follows:
* * * * * $CRON_WRAPPER "<job name>" "command"
which would record ...
0
votes
1answer
58 views
How to solve nsf-common related error when install zsh in ubuntu?
Everytime I install some kind of package, at the last phase, apt-get install could return a common-nfs related error. Why the installation can't be done without this error?
detailed pastebin here
...