Skip to main content

All Questions

Tagged with
101 votes
7 answers
37k views

How to use `which` on an aliased command?

Like most users, I have a bunch of aliases set up to give a default set of flags for frequently used programs. For instance, alias vim='vim -X' alias grep='grep -E' alias ls='ls -G' The problem is ...
Adrian Petrescu's user avatar
50 votes
5 answers
47k views

Is it possible to include file in config file of zsh? How?

I'd like to have a file eg. f with only zsh aliases (pureness reasons). Then I'd like to include f file in my .zshrc file, so that the aliases defined in f are visible in .zshrc. Is it possible? If ...
xliiv's user avatar
  • 899
40 votes
2 answers
38k views

alias vs export for simple commands

For simple commands like less, is it better to make an alias or to export the options? Is there any benefit of one over the other? For example, if I want less to always use the -R option to show raw ...
skittleys's user avatar
  • 645
37 votes
2 answers
79k views

How to reset a shell environment?

This issue has been bugging me for a while, and although I've thought I've found my answer through EnvWatcher, unfortunately it only works on Bash. And I use zsh. I would like to replicate the things ...
mhitza's user avatar
  • 566
29 votes
3 answers
30k views

Escaping quotes in zsh alias

Following on from this question about stripping newlines out of text, I want to turn this into a zsh alias as follows: alias striplines=' awk " /^$/ {print \"\n\"; } /./ {printf( \" %s \",$0);}"' I'...
Seamus's user avatar
  • 3,713
29 votes
2 answers
5k views

How to make the zsh "correct" functionality remember my spell-correction decisions

I have enabled correction (I wouldn't call it autocorrection specifically because of this issue) in zsh by enabling setopt correct in my .zshrc. Now, when I type dtae in a terminal, I get: dtae ...
shrx's user avatar
  • 445
26 votes
5 answers
14k views

Clear or disable aliases in zsh

I installed oh-my-zsh to make terminal use a bit easier. One thing that bugs me though is the prolific aliases added by it, like "ga", "gap", "gcmsg", "_", which are harder to remember than the ...
Siyuan Ren's user avatar
  • 1,382
25 votes
4 answers
15k views

Share aliases and PATH setting between zsh and bash

The shell that I normally use is zsh. I have several aliases to enable color in some programs such as ls and grep. I've also set my custom path so that I can execute programs in non-standard place (...
phunehehe's user avatar
  • 20.3k
25 votes
1 answer
5k views

how to find file defining an alias

I am having a problem I'm not sure how to get around. Somehwhere on my system, I have an alias defined as such: alias subl=\''/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl'\' I ...
Ali Samii's user avatar
  • 441
15 votes
4 answers
13k views

Using zsh autocompletion for alias

I have created a few aliases for git in zsh. For example: gch = git checkout, grb = git rebase --committer-date-is-author-date and some more complex useful zsh functions for git commands. But how can ...
Patrick Artounian's user avatar
14 votes
3 answers
8k views

Resolve all aliases in a zsh command line

I have nested aliases and I want to resolve all of them before executing the command. How do I do that? If there is a function that is not bound to any keys then M-x foobar is fine for me too. I ...
WeSenseASoulInSearchOfAnswers's user avatar
12 votes
5 answers
1k views

How can I "stack" shell aliases?

In my .profile (sourced in sh emulation mode from my .zshrc) I have the following snippet: if [ -f /usr/bin/pacmatic ]; then alias pacman=pacmatic fi # Colorized Pacman output alias pacman="...
strugee's user avatar
  • 15.1k
11 votes
3 answers
6k views

Difference between alias in zsh and alias in bash

I have searched around but could not find anything conclusive. Is there a difference between the alias command in zsh and the alias command in bash? If not, does it mean I can share a set of aliases ...
Zameer Manji's user avatar
11 votes
3 answers
1k 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 ...
Ole Tange's user avatar
  • 35.8k
9 votes
3 answers
6k views

sudo: nocorrect: command not found

I am using zsh and oh-my-zsh on Arch Linux. I am not able to make directory using mkdir edward@ArchLinux ~ $ sudo mkdir -p /samba/raspberry [sudo] password for edward: sudo: nocorrect: command ...
Alex Jones's user avatar
  • 6,383
9 votes
1 answer
6k views

How to overwrite aliases in my shell (Oh My Zsh)?

I would like to alias my ls command, but there is a previously defined alias for it which I believe gets invoked first before my definition! I am using .zshrc to define my alias, and here is what I ...
Farhad's user avatar
  • 93
8 votes
2 answers
2k views

zsh alias expansion

Is it possible to configure zsh to expand global aliases during tab completion? For example, I have the common aliases: alias -g '...'='../..' alias -g '....'='../../..' but when I type for example ...
Bryan Ward's user avatar
7 votes
5 answers
6k views

Get the expansion of an alias (in both bash and zsh)

I want to get the expansion of an alias. For example, if I have: alias g=hub alias cdh='cd $HOME' I want to have: expand_alias g == hub expand_alias cdh == cd $HOME The tricky thing is that the two ...
Tom Hale's user avatar
  • 31.2k
7 votes
3 answers
1k views

What is causing `diff` to run `git diff`?

I'd like to use diff as described here and in the documentation I see when I type man diff. However, when I type diff, what I get is this: ~ ❯❯❯ diff usage: git diff --no-index <path> <path&...
Ben Saufley's user avatar
7 votes
5 answers
6k views

Is it possible to define directory-sensitive aliases in zsh (or any other shell)?

I want to use different aliases (or perhaps: the same alias differently) depending on the current working directory. For example, I might want to use l as a shorthand for ls with some extra options. ...
k.stm's user avatar
  • 719
7 votes
1 answer
6k views

Zsh - alias -s with parameter

In zsh, I can specify default program to open which file extension like alias -s {mkv,mpg}='mplayer' . I runs fine but what I really want is to run mplayer <filename> & so it won't produce ...
Dzung Nguyen's user avatar
6 votes
2 answers
4k views

Make "." and "source" default to ~/.zshrc

I would like to source my ~/.zshrc by running . with no arguments. So this: $ . should do this: $ . ~/.zshrc I would like the normal functionality of . to remain unchanged. The only difference ...
Resigned June 2023's user avatar
6 votes
1 answer
3k views

What's the intended use case for COMPLETE_ALIASES in zsh?

For some months now, I have had setopt completealiases in my .zshrc. I haven't the faintest idea why I added it - most other things have comments or can be understood from neighbouring settings. ...
muru's user avatar
  • 73.9k
6 votes
1 answer
3k views

Run one command after another in zsh when Ctrl-C is pressed

I have recently moved to zsh from bash (on OSX). I have an bash alias I have used to run one program then another (even if previous program exits with error) on bash. I can't work out how to ...
ravenshill's user avatar
5 votes
3 answers
6k views

Automatically put an alias into ~/.bashrc or ~/.zshrc [duplicate]

Is there a command line util/script that automatically saves aliases? E.g. save-alias my-ip="curl ipecho.net/plain" and that will define an alias, then add/update it in ~/.bashrc or ~/.zshrc I was ...
Don Manley's user avatar
5 votes
2 answers
3k views

Forward aliases to child process

I have some aliases which are defined in /etc/zprofile (or /etc/profile for bash). Also $PATH gets manipulated there. I want to start an interactive shell from a shell which avoids the $PATH ...
pseyfert's user avatar
  • 888
4 votes
1 answer
584 views

How to trigger a 2nd command when a specific command is run in the shell?

I'll explain my question with example. I run $ python manage.py to perform some action. I want to run another command $ xyz , just when any user runs the previous command. Thus, from now on, ...
yask's user avatar
  • 153
4 votes
3 answers
8k views

zsh alias being overridden somehow

I'm on a system running OS X 10.8.5. I recently tried to alias ls to ls -G -la command. I opened up ~/.zshrc, put in the alias, relaunched the terminal, but the change didn't take effect. Upon ...
Jules's user avatar
  • 2,104
4 votes
3 answers
2k views

Automatically source a file when `cd` into a specific directory

I have couple of utility commands-and-aliases that are generic enough in any directory for my own requirement. But there are certain directory e.g. 'build', where I need a custom behaviour. To do this,...
mtk's user avatar
  • 27.8k
4 votes
4 answers
5k views

Does Bash and Zsh have a mode to echo what the alias expands to upon pressing Enter?

For example, if I have a alias dbmigrate='rails db:migrate' is there a mode or simple way to configure in Bash and Zsh so that when I type in the shell: $ dbmigrate # press Enter it will echo ...
nonopolarity's user avatar
  • 3,109
4 votes
1 answer
3k views

How to declare some aliases dynamically in zsh?

I would like to declare a few shortcut commands to switch between my various coding projects, so I have come up with the following script. projects=$(ls -d ~/Workspace/*/) prefix="/Users/myuser/...
le-doude's user avatar
  • 143
4 votes
1 answer
363 views

How can I alias a history expansion in zsh?

I want this to work (it needs extendedglob and histsubstpattern): alias ri='^(#b)E(?)^E${(l:2::0:)$((match[1]+1))}' But it doesn't: $ alias sss='^(#b)E(?)^E${(l:2::0:)$((match[1]+1))}' ...
HappyFace's user avatar
  • 1,620
4 votes
1 answer
302 views

Tab complete global alias names not at the beginning of a line

I have a bunch of aliases like this alias -g foo=cmd1 alias -g faz=cmd2 alias -g fam=cmd3 At the shell (I'm using zsh) I want to be able to type echo fa<TAB> and be prompted for faz or fam ...
Justin Garrison's user avatar
3 votes
1 answer
5k views

How to create an alias for two Git commands that use a parameter? [duplicate]

I regularly have to delete a local and remote Git branch. Therefore, I run the following commands: $ git branch -d feature-branch $ git push --delete origin feature-branch Since I mostly execute ...
JJD's user avatar
  • 587
3 votes
2 answers
1k views

How to create hyphen alias for zsh?

I am using zsh and oh-my-zsh on Ubuntu. To change into the recent directory in the past there was an alias set to - which is the same as cd -. Somehow the alias disappeared at my machine. This might ...
JJD's user avatar
  • 587
3 votes
2 answers
856 views

Making an alias which maps arguments to the middle of the command

I want to alias killapp X to pidof X | xargs kill or kill `pidof X`, but I can't think of a way to do this with just an alias on killapp. How could I do this so I don't have to do killapp X` ?
aaazalea's user avatar
  • 193
3 votes
1 answer
2k views

Using heredoc in zsh aliases

I would like to use heredoc in a zsh alias, for example: alias runthing="cd ~; date << HERE date HERE" However every time I run this alias, the shell acts as if I have not terminated the ...
Brian Hamill's user avatar
3 votes
3 answers
423 views

How to alias a command with '

I wanted to make an alias turn caps lock off: python -c 'from ctypes import *; X11 = cdll.LoadLibrary("libX11.so.6"); display = X11.XOpenDisplay(None); X11.XkbLockModifiers(display, c_uint(0x0100), ...
jinawee's user avatar
  • 187
3 votes
2 answers
944 views

How to create an alias that launches zathura with tabbed

So tabbed outputs it's xid when you run it. How could I put this into an alias dynamically? I'm looking to do something like: alias zathura = tabbed -c zathura -e ${tabbed Xid goes here} & disown
vimdiesel's user avatar
3 votes
1 answer
4k views

How to pipe into zsh with alias expansion?

I'm trying to run a line from history by piping it into zsh with: cat ~/.zsh_history | cut -d ';' -f 2 | sk --tac | zsh This works if the line I pick interactively with sk is a command that is ...
agentofuser's user avatar
3 votes
1 answer
294 views

How can I use !! in zsh alias

I am trying to create an alias that builds upon my previous command. Say I run ag foo After looking at the list I want to be able to use those results in vim so I do vim -q<(!! --vimgrep) The ...
chrisortman's user avatar
3 votes
1 answer
41 views

On using $hash_array[$(global_alias)]

Identical code works on one system, fails on another: % zsh --version zsh 5.0.7 (x86_64-pc-linux-gnu) % typeset -A frobozz % alias -g foo='echo xyz' % frobozz[$(foo)]=9 % echo ${(kv)frobozz} xyz 9 % ...
kjo's user avatar
  • 15.6k
2 votes
2 answers
748 views

How to add an alias for 'git add **/'

I can't seem to add an alias for git add **/ I think those two asterisks is causing an issue, or it could be that forward slash. How do I solve this? So far I have tried alias ga='git add **/' When ...
Faraz Durrani's user avatar
2 votes
1 answer
361 views

Alias piping into awk

I am trying to create an ll with awk pipe alias. I am trying to escape the apostrophes using the following answers. alias lh= `ll -h | awk {'print $9, \"-\" ,$5, \"-\", $8, \"...
zerberus's user avatar
2 votes
1 answer
1k views

zsh alias with arguements

I have an alias for neovim-qt thus defined: gvim='nvim-qt --geometry 500x320 --' This allows me to call gvim foo.py ook.py and have a QT window running neovim with two tabs, one for each file. ...
Sardathrion - against SE abuse's user avatar
2 votes
2 answers
287 views

Turn off one flag of command and infinite recursion

Since it overwrites my history when used in multiple terminals, I want to turn off the functionality fc -W. Unfortunately I have a habit of typing it often. I think it's not possible to make an alias,...
pfnuesel's user avatar
  • 5,927
2 votes
2 answers
1k views

Execute zsh alias when name contains a hyphen

A stock-standard zsh behaves as follows with an alias with a - in it, eg: a-a: % zsh -f svelte% alias a-a=date svelte% a-a Sun 19 Jul 2020 17:20:05 +07 My configuration has it behave as follows: % ...
Tom Hale's user avatar
  • 31.2k
2 votes
2 answers
965 views

Why do I have to use this command twice to execute it?

I made an alias alias goto="cd $@ && source ~/.zshrc" and it works, but only if I execute it twice. Even after I execute it twice in one shell, and if I want to move to another dir, ...
Leo1807's user avatar
  • 23
2 votes
1 answer
806 views

alias ? not working in zsh

I was lead to believe that there were no differences between aliases in zsh and bash, however that appears to not be the case. I had an alias that would help me familiarize myself with the command ...
anAlias's user avatar
  • 21
2 votes
2 answers
401 views

create an alias on ZSH but need to type it twice

I'm trying to create an alias on ZSH. The aim of the alias is to activate a python virtualenv. I've put a line in my .zshrc alias SOU="source /home/andykw/.zshrc && source $(setopt ...
Andy K's user avatar
  • 179

15 30 50 per page