iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
⏱️

My Everyday Zsh Aliases and Functions

に公開

I use zsh, but it's probably about the same for bash.
The ~~~ in the headings indicate omissions because the options are long.

gst: git status

alias gst='git status'

gda: git --no-pager diff

alias gda='git --no-pager diff'

gl: git log ~~~

Easy-to-read git log options I found somewhere before. Since they're long, I made them into an alias.

alias gl='git log --all --date-order --date=format:"%Y-%m-%d" --graph --format=" <%h> %ad [%an] %C(green)%d%Creset %s"'

gla: git --no-pager log ~~~

Since gl uses a pager, this turns it off. --no-pager is a git option, not a log option, so I can't reuse gl...

alias gla='git --no-pager log --all --date-order --date=format:"%Y-%m-%d" --graph --format=" <%h> %ad [%an] %C(green)%d%Creset %s"'

gls: Short version of gl

A version limited to the last 15 commits. It's generally useful for checking before pushing. Since -n is a log option, I'm reusing gl.

alias gls='gl -n 15'

gc(): git add . && git commit

It's not exactly a good practice (as it can lead to neglecting verification), but it's very convenient.

function gc() {
  git add .
  git commit -m "$1"
}

touch-p(): Combination of mkdir -p and touch

A function that creates directories and files simultaneously. While aliases are simple replacements, functions allow you to use arguments, which makes this possible.

function touch-p() {
    mkdir -p $(dirname "$1") && touch "$1"
}

touch -p ~/foo/bar/foobar.md

ff: fastfetch

Quite handy when you have many things for blogs or public sharing.

alias ff='fastfetch'

cdx: cd ~~~

I create shortcuts to various folders using cd + the initials of the folder name.

alias cdd='cd $HOME/Develop/'
# Others like iCloud folders on Mac

nv: neovim

It's a small thing, but surprisingly useful.

alias nv='nvim'
alias nvd='nvim .'

copy: pbcopy (Mac's copy feature)

On Mac, there is a command to copy from the terminal to the OS clipboard, but since I can never remember the name, I made it copy.

alias copy='pbcopy'

Bonus rl: rlwrap sbcl

Using raw sbcl is too inconvenient because arrow keys don't work, so I use rlwrap. I've had trouble after overwriting the sbcl command itself before, so I use a different name.

alias rl='rlwrap sbcl'

https://github.com/Uliboooo/dotfiles

Discussion