JustToThePoint English Website Version
JustToThePoint en español

Shells: Zsh & Oh-my-zsh. Aliases. Fish

Play around with your command shell, and you’ll be surprised at how much more productive it makes you, The Pragmatic Programmer

Unix shells are interactive interfaces that allow users to interact with the Operating System by executing commands and utilities. There are three main shells: bash, Zsh, and fish.

All you need is #!/bin/bash

Z shell

Some features: If you want to change directory, it is not necessary to enter the cd command (automatic cd), i.e. Documents instead of cd Documents and you don’t have to type whole directory names either, ls Dro/do/Ba(<Tab>) becomes Dropbox/docs/Basic. tree -<Tab> suggest a list of options for tree, with short descriptions, ls **/Linux.md performs a recursive search and returns Dropbox/docs/Linux.md

  1. Installation: brew install zsh zsh-autosuggestions (macOS), sudo apt install zsh && sudo apt-get install powerline fonts-powerline (Ubuntu), sudo pacman -S zsh zsh-completions powerline powerline-fonts (Arch)
  2. Check the Zsh version by typing zsh ‐‐version
  3. Set zsh as the default shell. Make sure that zsh is installed and is an accepted shell: cat /etc/shells, then make it your default shell by using chsh -s /usr/bin/zsh username. After that, you need to log out, then log back in for the changes to take effect. Don’t worry, you can always revert to Bash by typing: chsh -s $(which bash).
  4. First run. When you first open a terminal, you’ll be greeted by the Z Shell configuration function for new users with a menu. Select 2, Populate your ~/.zshrc with the configuration recommended by the system administrator and exit.
    sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

After editing the configuration file for Z shell, you need to either start a new shell instance or type: source ~/.zshrc to apply the changes you have just made. Next time, you could use the alias “szsh”. zsh

Aliases and Functions

Aliases are essentially shortcuts, a means of avoiding typing or remembering a long command sequence that you use often.

# =============================================================================
# ~/.zsh_aliases  (stow package: zsh/.zsh_aliases)
# An alias is a short text substitution: it is expanded when you press Enter.
# Anything that needs arguments in the middle, or logic, lives in ~/.zsh_functions.
# Loaded AFTER Oh My Zsh, so an alias here overrides a plugin alias of the same name.
# `(( $+commands[tool] ))` is true when `tool` is installed, so nothing breaks on a new Mac.
# =============================================================================

# ---- Navigation -------------------------------------------------------------
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias dots='cd "$DOTFILES"'
# AUTO_CD is on: typing a folder name alone also changes into it. `d` (OMZ) lists the
# folder stack, `cd -2` jumps back to entry 2.

# ---- Listing: eza when installed (brew install eza), plain ls otherwise ----------
if (( $+commands[eza] )); then
    alias ls='eza --icons=auto --group-directories-first'
    alias ll='eza -lah --git --header --icons=auto --group-directories-first'   # long, hidden, git status
    alias la='eza -a --icons=auto --group-directories-first'
    alias lt='eza --tree --level=2 --icons=auto --git-ignore'                   # tree, 2 levels
else
    alias ls='ls -G'
    alias ll='ls -lAhG'
    alias la='ls -A'
fi

# ---- Editor / shell ------------------------------------------------------------
if (( $+commands[nvim] )); then
    alias v='nvim'
    alias vim='nvim'
    alias vi='nvim'
fi
alias ezsh='$EDITOR ~/.zshrc'
alias ealias='$EDITOR ~/.zsh_aliases'
alias efunc='$EDITOR ~/.zsh_functions'
alias reload='exec zsh'                          # a fresh shell: cleaner than `source ~/.zshrc`
alias zshbench='time zsh -i -c exit'             # startup time, aim for < 0.3 s
alias zshprof='ZPROF=1 zsh -i -c exit'           # which part of startup is slow

# ---- Git -------------------------------------------------------------------------
# Not defined here on purpose, the Oh My Zsh `git` plugin already has better ones:
#   gst = status, gsb = status -sb (your old `gs`), glog = log --oneline --graph --decorate
#   gl  = git pull (your old `gl` would have overridden it), gp = push, gco, gcb, gaa, gcmsg
# Your old `gs` also hid Ghostscript, whose command is `gs`.
(( $+commands[lazygit] )) && alias lg='lazygit'

# ---- Local AI (Ollama + Continue) -------------------------------------------------
alias ai-on="$DOTFILES/scripts/ollama-start.sh"      # set options, quit apps, load the model
alias ai-off="$DOTFILES/scripts/ollama-stop.sh"      # unload the model, quit Ollama
alias ai-ps='ollama ps'                              # what is loaded, "100% GPU" is what you want
alias ai-ls='ollama list'                            # downloaded models

# ---- Clipboard (macOS: pbcopy/pbpaste, not xclip) -------------------------------------
alias copy='pbcopy'                                  # git diff | copy
alias paste='pbpaste'

# ---- System ------------------------------------------------------------------------
alias df='df -h'                                     # human-readable sizes
alias du1='du -h -d 1 | sort -hr'                    # size of each item in this folder, biggest first
alias mem='top -l 1 -s 0 | grep PhysMem'             # macOS has no `free` command
alias ports='lsof -iTCP -sTCP:LISTEN -n -P'          # what is listening on which port
alias path='print -l $path'                          # one PATH entry per line
alias flushdns='sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder'
alias myip='curl -s https://api.ipify.org; echo'     # public IP (https, unlike the old http one)
alias localip='ipconfig getifaddr en0 || ipconfig getifaddr en1'   # Mac Studio: en0 = Ethernet or Wi-Fi
alias grep='grep --color=auto'
alias cp='cp -i'                                     # ask before overwriting
alias mv='mv -i'

# ---- Homebrew --------------------------------------------------------------------------
alias brewup='brew update && brew upgrade && brew cleanup'
alias brewdump='brew bundle dump --force --file="$DOTFILES/Brewfile"'   # save installed apps into your repo

# ---- macOS -------------------------------------------------------------------------------
alias o='open'
alias oo='open .'                                    # open this folder in Finder
alias ghostty-validate='ghostty +validate-config'

# ---- Files: preview with fzf + bat ----------------------------------------------------------
alias preview="fzf --preview 'bat --style=numbers --color=always {}'"

# ---- Optional, only if installed ---------------------------------------------------------------
if [[ -f ~/.config/myquotes/quotes ]] && (( $+commands[fortune] )); then
    alias fortune='fortune ~/.config/myquotes/quotes'   # your own quotes (needs: strfile quotes)
fi
(( $+commands[curseradio] )) && alias radio='curseradio'

If you want to know more about cat, exa, fzf, youtube-dl, and ripgrep, read our article Awesome command linux tools: bat, fzf, exa, ripgrep.

# =============================================================================
# ~/.zsh_functions  (stow package: zsh/.zsh_functions)
# A function is a small program living in your shell. Unlike an alias it can take arguments
# anywhere ("$1", "$@"), use variables and make decisions.
# =============================================================================

# mkcd dir: create a folder (and parents) and go into it.
mkcd() {
    [[ -n $1 ]] || { echo "usage: mkcd "; return 1; }
    mkdir -p -- "$1" && cd -- "$1"
}

# calc "3*4"  ->  12      (bc -l = math library, decimals work: calc "10/3")
calc() { bc -l <<< "$*" }
alias calc='noglob calc'     # noglob: `calc 3*4` also works without quotes

# urlencode "hello world"  ->  hello+world
urlencode() {
    python3 -c 'import sys, urllib.parse as u; print(u.quote_plus(" ".join(sys.argv[1:])))' "$@"
}

# myripgrep : search inside my Hugo content folder.
myripgrep() { rg "$@" "$HOME/JustToThePoint/content/" }

# mysearch : same search, and open the same words in Google
# (macOS: `open`, there is no xdg-open).
mysearch() {
    rg "$@" "$HOME/JustToThePoint/content/"
    open "https://www.google.com/search?q=$(urlencode "$*")"
}

# searchEdit: fuzzy-find a config/script file with a preview, then open it in $EDITOR.
# Handles spaces in names (-print0 / --read0 / xargs -0) and skips folders that do not exist.
searchEdit() {
    local -a dirs existing
    local d
    dirs=("$HOME/.config" "$DOTFILES" "$HOME/.local/bin" "$HOME/Dropbox")
    for d in $dirs; do [[ -d $d ]] && existing+=("$d"); done
    (( ${#existing} )) || { echo "searchEdit: no folder to search"; return 1; }
    find "${existing[@]}" -type f -not -path '*/.git/*' -print0 \
        | fzf --read0 --print0 --preview 'bat --style=numbers --color=always {}' \
        | xargs -0 -o ${=EDITOR}
}

# ytmp3 : download the audio of a video as mp3 into ~/Music.
# youtube-dl is unmaintained, yt-dlp replaces it (brew install yt-dlp ffmpeg).
# -P sets the download folder, so your shell stays where it is (the old version did cd).
ytmp3() {
    (( $+commands[yt-dlp] )) || { echo "brew install yt-dlp ffmpeg"; return 1; }
    yt-dlp --extract-audio --audio-format mp3 -P "$HOME/Music" -o '%(title)s.%(ext)s' "$@"
}

# playmp3: play all mp3 files in ~/Music in random order (brew install mpv). Quit with q.
playmp3() {
    (( $+commands[mpv] )) || { echo "brew install mpv"; return 1; }
    mpv --no-video --shuffle "$HOME"/Music/*.mp3
}

# free: memory summary (macOS has no `free`). Useful to check before loading a big model.
free() {
    top -l 1 -s 0 | grep PhysMem
    memory_pressure | grep 'free percentage'
}

# killport : stop whatever is listening on that port (a dev server that did not exit).
killport() {
    [[ -n $1 ]] || { echo "usage: killport "; return 1; }
    local pids
    pids=$(lsof -ti tcp:"$1" -sTCP:LISTEN) || { echo "nothing is listening on port $1"; return 1; }
    echo "killing PID(s): ${pids//$'\n'/ }"
    echo "$pids" | xargs kill
}

# weather [city]: one-line weather from wttr.in
weather() { curl -s "wttr.in/${1:-}?format=3" }

# Archives: the Oh My Zsh `extract` plugin gives you `extract ` and `x `.

Fish

fish is a smart and user-friendly command line shell.

  1. Install fish shell: sudo apt install fish
  2. Make it your default shell: chsh -s /usr/bin/fish. If you want to change back to your bash shell: chsh -s /usr/bin/bash
  3. It performs syntax highlighting as you type. Invalid commands are colored red by default: ct. As you type, it will suggest commands to the right of the cursor. When the text becomes a valid command, it is shown in a different color: cd /usr/share/doc/xmobar/examples.
  4. Tab Completions work out of the box: mk(Tab) -commands-, mkdir (Make directories); /etc/m(Tab) -paths-; rm -(Tab) -arguments, -f (Never prompt for removal)…
  5. You can get help in a web browser (help) or using man in the terminal (man fish).
  6. Install Fisher, a plugin manager for Fish: curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher. You could also install some plugins, e.g., fisher install jethrokuan/z; z is a port of z for the fish shell, eg. z fish will likely lead you to .config/fish. Another nice plugin is Sparklines for fish: fisher install jorgebucaran/spark.fish
  7. Let’s edit Fish’s configuration file: vim /home/nmaximo7/.config/fish/config.fish
neofetch
# Aliases
alias efish 'vim ~/.config/fish/config.fish'
alias evim 'vim ~/.vimrc'
alias cat 'bat'
alias rfish 'source ~/.config/fish/config.fish'
alias tobash="sudo chsh $USER -s /bin/bash && echo 'Now log out.'"

function fish_greeting
    fortune | cowsay
end

# PROMPT: https://fishshell.com/docs/current/cmds/fish_prompt.html
function fish_prompt -d "Write out the prompt"
    # This shows up as USER@HOST /home/user/ >, with the directory colored
    # $USER and $hostname are set by fish, so you can just use them
    # instead of using `whoami` and `hostname`
    printf '%s@%s %s%s%s > ' $USER $hostname \
        (set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
end
Bitcoin donation

JustToThePoint Copyright © 2011 - 2026 Anawim. ALL RIGHTS RESERVED. Bilingual e-books, articles, and videos to help your child and your entire family succeed, develop a healthy lifestyle, and have a lot of fun. Social Issues, Join us.

This website uses cookies to improve your navigation experience.
By continuing, you are consenting to our use of cookies, in accordance with our Cookies Policy and Website Terms and Conditions of use.