DEV Community

Cover image for My Shell Aliases
Nick Taylor
Nick Taylor Subscriber

Posted on • Originally published at iamdeveloper.com on

My Shell Aliases

Everyone has their favourite aliases for git and the shell. I have written about my git aliases before but not my shell aliases.

It is not a long list, but I have some that I find useful that you may find useful as well. Currently, my preferred shell is zsh. Here is what I currently have in my config.

alias rimraf='rm -rf'
alias flushdns='sudo killall -HUP mDNSResponder'
alias zshconfig='vi ~/.zshrc'
alias nr='npm run'
alias ni='npm i'
alias y='yarn'
alias story='yarn storybook'
alias code='code-insiders'
alias tw='yarn test:watch'
alias '$'=''
alias zshconfig='vi ~/.zshrc'
Enter fullscreen mode Exit fullscreen mode

What's in your shell aliases?

Photo by Krzysztof Niewolny on Unsplash

Top comments (16)

Collapse
 
dechamp profile image
DeChamp

Love this! I have some of my own collection as well. A mix of alias and functions.

# A nice little readme function, to make a README file into a webpage
# usage: rmd path/to/README.md
rmd () {
    grip -b $1 &
    TASK_PID=$!
    sleep 10
    kill $TASK_PID
}

# Takes a video and converts it to mp4 for web
# usage: genwebmp4 path/to/video.ext
# ffmpeg can handle many ext type so you are not limited (.mov, .avi and so on)
genwebmp4 () {
    ffmpeg -i $1 -vcodec h264 -acodec aac -strict -2 $2
}

# Takes a video and converts it to webm for web
# usage: genwebm path/to/video.ext
# ffmpeg can handle many ext type so you are not limited (.mov, .avi and so on)
genwebm () {
    ffmpeg -i $1 -c:v libvpx-vp9 -b:v 2M -pass 1 -c:a libopus -f webm /dev/null && \
        ffmpeg -i $1 -c:v libvpx-vp9 -b:v 2M -pass 2 -c:a libopus $2
}

#usage: genvideothumb path/to/video.ext
genvideothumb () {
    ffmpeg -ss 00:00:01  -i $1 -vframes 1 -q:v 2 $2
}

# for those who struggle spelling! This will take your best guess and give you a list of what you probably meant.
#usage: spl paranoya 
# & paranoya 8 0: paranoia, Parana, paranoiac (as you see the first option after the 0, gives the correct spelling
spl () {
    aspell -a <<< "$1"
}

#Clean up your git branches that have already been merged in.
#usage: best to first do a git fetch --all and then run gitCleanBranches
gitCleanBranches() {
    git branch --merged | egrep -v "(^\*|master|develop)" | xargs git branch -d
}

#usage: wavToMp3 path/to/file
# no extension needed
wavToMp3() {
    ffmpeg -i $1.wav -codec:a libmp3lame -qscale:a 2 $1.mp3
}

#usage: mp3ToOgg path/to/mp3's
# no extension needed
mp3ToOgg() {
    for file in *.mp3
        do ffmpeg -i "${file}" "${file/%mp3/ogg}"
    done
}

alias itunes='/usr/local/bin/itunes'
alias storybook="start-storybook -p 9001 -c .storybook"
alias ll='ls -al'
alias dc='docker-compose '
alias dci='docker-compose images'
alias dps='docker ps'
alias dcreup='docker-compose down && docker-compose up --build'
alias deleteMergedBranches='git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d'
alias dstop='docker stop $(docker ps -a -q)'
alias sf='bin/console ' //symfony console
alias memhog='ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head'
alias brewup='brew update; brew upgrade; brew prune; brew cleanup; brew doctor'

I also use oh-my-zsh, with many of it's oh-my-zsh plugins. it's osx plugin is pretty awesome when working on mac, giving you ability to open current paths in the finder, or getting the current selected file in the finder, as a path in the terminal.

There are so many pluigns, you'll have to check out the oh-my-zsh plugins list.

Collapse
 
deciduously profile image
Ben Lovy

Definitely stealing those ffmpeg lines.

Collapse
 
dechamp profile image
DeChamp

please do! they helped me a lot.

Collapse
 
vonheikemen profile image
Heiker

Why not?

alias -- -='cd -'

alias cp="cp -i"
alias df='df -h'

# alias ls='ls --color=auto'
alias ls='exa'
alias grep='grep --colour=auto'
alias egrep='egrep --colour=auto'
alias fgrep='fgrep --colour=auto'

alias np="pnpm"
alias npr="pnpm run"

alias lzg="lazygit"

alias ta="tmux attach -t"
alias ts="tmux new-session -s"
alias tl="tmux list-sessions"
alias tmus='tmux new-session -A -D -s music "$(which cmus)"'

alias pomd='tmux new-session -A -D -s pomodoro'
alias pmd-start='pomd gone -e "notify-send -u critical Pomodoro Timeout"'

alias vi-s="nvim -S Session.vim"

alias dcc="docker-compose"

alias doc-start="systemctl start docker"
alias doc-ls="docker ps -a"

# alias la='ls -lAh'
alias la='exa --git --header --long --all'

alias yt="youtube-dl -f 'bestvideo[height<=720]+bestaudio/best[height<=720]'"
alias dot='yadm'
Enter fullscreen mode Exit fullscreen mode
Collapse
 
deciduously profile image
Ben Lovy • Edited

alias y='yarn' # I am lazy, one character FTW. YOLO

Hell yes. I still haven't outgrown my Gentoo phase, so I update with u:

alias eup='sudo emerge -avtuDN --with-bdeps=y --keep-going @world'
alias u='sudo eix-sync && eup'

On my aging laptop running Void:

alias u='sudo xbps-install -Su'

There's also this monstrosity for building a new kernel in /root/.bashrc:

alias dokern='cd /usr/src/linux && mount /boot && make clean && make distclean && make mrproper && zcat /proc/config.gz > .config && make -j12 && make modules_install && make install && grub-mkconfig -o /boot/grub/grub.cfg && emerge -avt @module-rebuild && umount /boot && cd -'

I'm not even sorry. I had a similar line for cleaning up artifacts from an old kernel but it got gross enough to merit its own script.

In a similar vein to eup for emerge, there's Rust and OCaml toolchains:

alias oup='opam update && opam upgrade'
alias rup='rustup update && cargo install-update -a'
Collapse
 
mitchartemis profile image
Mitch Stanley

My Bash Equivalent aliases

alias cpsh='cat ~/.ssh/id_rsa.pub | pbcopy' # copy ssh key to clipboard (macOS)
alias ef='nvim ~/.config/fish/config.fish' # open fish config
alias eh='sudo nvim /private/etc/hosts' # edit hosts file
alias esh='nvim ~/.ssh/config' # edit SSH config
alias ev='nvim ~/.vimrc' # Edit vim config
alias serve='ruby -run -ehttpd . -p8000' # Quick static web server in current directory
alias whatsmyip='curl ifconfig.co' # Get my IP address

# Time warrior functions, these are all for time tracking with Time Warrior
alias tsi='timew summary :ids'
alias tsl='timew summary :lastweek :ids'
alias tsw='timew summary :week :ids'
Enter fullscreen mode Exit fullscreen mode

My Fish functions (What fish uses instead of Alias)

# copy ssh key to clipboard (macOS)
function cpsh
    cat ~/.ssh/id_rsa.pub | pbcopy
end

# open fish config
function ef
    nvim ~/.config/fish/config.fish
end

# edit hosts file
function eh
    sudo nvim /private/etc/hosts
end

# edit SSH config
function esh
    nvim ~/.ssh/config
end

# Edit vim config
function ev
    nvim ~/.vimrc
end

# Quick static web server in current directory
function serve
    ruby -run -ehttpd . -p8000
end

# Time warrior functions, these are all for time tracking with Time Warrior
function tsi
    timew summary :ids
end

function tsl
    timew summary :lastweek :ids
end

function tsw
    timew summary :week :ids
end

# Get my IP address
function whatsmyip
    curl ifconfig.co
end
Enter fullscreen mode Exit fullscreen mode
Collapse
 
abhinav1217 profile image
Abhinav Kulshreshtha • Edited

I don't believe in one character aliases. I utilize tabs to reduce keystrokes. My aliases are some per-configuration for tools. And some personalized tools are prefixed with fl_ or with flp_


#-------------------------------------------------------------
# Aliases for windows like functionality
#-------------------------------------------------------------

alias cmd="gnome-terminal"
alias cd..="cd .."
alias md="mkdir -p"
alias cls="clear"
alias ipconfig="ifconfig"
#-------------------------------------------------------------
# Aliases for sane functionality
#-------------------------------------------------------------

alias rm="rm -rf --preserve-root"
alias lla="ls -la --color=auto"
alias lsd="ls -d */ --color=auto"
alias lld="ls -ld */ --color=auto"
alias llf="ls -al --color=auto | grep '^[-l]'"
alias lsf="ls -a --color=auto | grep '^[-l]'"
alias cd-="cd -"
alias cd~="cd ~"
alias cdd="cd -P"


#-------------------------------------------------------------
# App Specific Aliases 
#-------------------------------------------------------------

#  Youtube-dl - dnf install youtube-dl ffmpeg ffmpeg-libs

alias youtube-dl-mp3="youtube-dl -x --audio-format mp3 "
alias youtube-dl-playlist="youtube-dl -cio '%(autonumber)s-%(title)s.%(ext)s' "

# Hub - https://hub.github.com/
alias git="hub"

#-------------------------------------------------------------
# Simple docker 
#-------------------------------------------------------------


# Remove all the <none> images. Even though it is not recommended.
alias fl_docker_remove_dangling='docker rmi $(docker images -f dangling=true -q)'

# Stop all running docker containers.
alias fl_docker_stop_all='docker stop $(docker ps -aq)'

# Kill all running containers.
alias fl_docker_kill_containers='docker kill $(docker ps -q)'

# Delete all stopped containers: 'docker rm $(docker ps -a -q)'
alias fl_docker_clean_containers='docker container prune'

# Delete all saved images:  'docker rmi $(docker images -q)'
alias fl_docker_clean_images='docker image prune'

# Delete all containers and images
alias fl_docker_clean_all='docker system prune'

# Restart all containers
alias fl_docker_restart_all='docker restart $(docker ps -a -q)'

# Start all stopped containers:
alias fl_docker_restart_stopped='docker start $(docker ps -a -q -f status=exited)'



#-------------------------------------------------------------
# Better progressbar in axel 
#-------------------------------------------------------------

alias axel="axel -d"

#-------------------------------------------------------------
# Mimic the behavior of Mac Open Command while preserving the 
# errors generated.
#   N.B.  Replaced by much more roubust open function.
#-------------------------------------------------------------

#alias open="xdg-open &>$HOME/.xsession-errors"

#-------------------------------------------------------------
# Search History.
#   Usage: histg <keyword>
#-------------------------------------------------------------

alias histg="history | grep"

#-------------------------------------------------------------
# Show which applications are connecting to the network.
#-------------------------------------------------------------

alias listen="lsof -P -i -n" 

#-------------------------------------------------------------
# Show the active ports
#-------------------------------------------------------------

alias show-port='netstat -tulanp'

#-------------------------------------------------------------
# Ubuntu like update-grub command.
#-------------------------------------------------------------

alias update-grub='sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg'
Collapse
 
abhinav1217 profile image
Abhinav Kulshreshtha

I also have some utility functions like



backup() { cp "$1"{,.bak};} 
mcd() {   [ -n "$1" ] && mkdir -p "$@" && cd "$1";   }
psx() { ps -ax | grep -v grep | grep "$@"; }function psx() { ps -ax | grep -v grep | grep "$@"; }

pskill(){
    ps aux | grep "$1" | grep -v grep | awk '{print $2;}' | while read p; do kill -9 $p; done
}


extract() { 
    if [ -f $1 ] ; then 
      case $1 in 
        *.tar.bz2)   tar xjf $1     ;; 
        *.tar.gz)    tar xzf $1     ;; 
        *.bz2)       bunzip2 $1     ;; 
        *.rar)       unrar e $1     ;; 
        *.gz)        gunzip $1      ;; 
        *.tar)       tar xf $1      ;; 
        *.tbz2)      tar xjf $1     ;; 
        *.tgz)       tar xzf $1     ;; 
        *.zip)       unzip $1       ;; 
        *.Z)         uncompress $1  ;; 
        *.7z)        7z x $1        ;; 
        *)     echo "'$1' cannot be extracted via extract()" ;; 
         esac 
     else 
         echo "'$1' is not a valid file" 
     fi 
}

#-------------------------------------------------------------
# Mimic the behavior of Mac Open Command while preserving the 
# errors generated
#-------------------------------------------------------------

open() {
    if [ $# -eq 0 ]
    then    
        xdg-open .;
    else
        xdg-open "$@" &>/home/Abhinav/.xsession-errors;
    fi
}

Collapse
 
nickytonline profile image
Nick Taylor

I use g for git as well. 🔥 I updated the post. I must have missed that line as I was only copying part of my .zshrc file. 🙃

Collapse
 
anwar_nairi profile image
Anwar

Ubuntu update on demand:

alias UPDATE='sudo apt -y update && sudo apt -y upgrade && sudo apt -y full-upgrade && sudo apt -y autoremove && sudo apt clean'

Open this alias file (I use Visual Studio Code, hence the code):

alias OPENALIAS='code $HOME/.bash_aliases &'

Load aliases:

alias LOADBASHRC='source ~/.bashrc'
Collapse
 
highcenburg profile image
Vicente G. Reyes

Here's mine

alias cookiecutter="cookiecutter https://github.com/pydanny/cookiecutter-django"
alias python="python3"
alias pip="pip3"
alias run="python manage.py runserver"
alias make="python manage.py makemigrations"
alias migrate="python manage.py migrate"
alias run_environ='source env/bin/activate'
Collapse
 
nickytonline profile image
Nick Taylor

If you're wondering what Edge doing in there, I decided to take it for a spin for the next little while as it is a new browser on the block.

It is Chromium-based, so I expect it to pretty much behave like Chrome, and Brave, another browser I was using. I am still curious what will make someone grab one Chromium browser over the other. I wrote about it here.

I think in the case of Edge, most people that get new PC laptops/desktops will probably just go with it unless they are already a die hard Chrome fan, but we will see.

Collapse
 
moopet profile image
Ben Sinclair

zshconfig saves one character from vi ~/.zshrc at the expense of having a command that only works on your own systems.

That edge one makes sense, though.

Collapse
 
jsvnm profile image
jsvnm

alias fu=‘sudo $( fc -ln -1 )’
that is, “what i just said but with sudo at beginning now will you do it”

Collapse
 
jeffshomali profile image
Jeff Shomali

lias chrome= should be alias chrome.

Collapse
 
rjrobinson profile image
R.J. Robinson

alias eat='rm -rf'