Your best terminal aliases

MoriGM@feddit.de to Linux@lemmy.ml – 30 points –

What are your most liked alias for long commands or just to give them better names.

Mine are:

alias load="source .load.sh"
alias eload="$EDITOR .load.sh"
alias gpush="git push"
alias gadd="git add --all"
alias gcommit="git commit -m "
alias gst="git status -s"
alias gpull="git pull"
66

mkcd() { mkdir -p “$1” && cd “$1”; }

Make a directory and immediately cd into it. I rarely make a directory and not cd into it.

Uuuuh needed this one so many times.

My app keeps crashing. That's the older version of my alias.

mkcd() { mkdir -p "$1" && cd "$1"; }

alias ..='cd ..'

My variant (u mean "up" in my head)

alias u  ='cd ..'
alias uu ='cd ../..'
alias uuu='cd ../../..'

Here are mine. Sorry for the mouth full, but I think people may benefit from some of these :)

alias ll="ls -alkhF"
alias l="ls -1"

# BE CAREFUL WITH THIS AND COULD RETURN COLOR KEYCODES INTO PIPES ETC...
alias grep='grep --color=always' 

alias db='dotnet build'

alias gs='git status'
alias gf='git fetch'
alias gl='git pull'
alias gp='git push'
alias gpt='git push --tags'
alias gP='git push --force-with-lease'
alias ga='git add'
alias gd='git diff'
alias gw='git diff --word-diff'
setopt interactive_comments
preexec(){ _lc=$1; }
alias gcm='git commit -m "${_lc#gcm }" #'

# THE BELOW TO BE USED ALONG WITH THE FOLLOWING GIT ALIASES:
#[alias]
#	logo = log --pretty=tformat:'%C(auto,red)%m %C(auto,yellow)%h%C(auto,magenta) %G? %C(auto,blue)%>#(12,trunc)%ad %C(auto,green)%<(15,trunc)%aN%C(auto,reset)%s%C(auto,red) %gD %D' --date=short
#	adog = log --all --decorate --oneline --graph
#	dog = log --decorate --oneline --graph

alias glog='git logo'
alias gdog='git dog'
alias gadog='git adog'

alias gb='git branch'
alias gba='git branch --all'
alias gco='git checkout'
alias gm='git merge'
alias gt='git tag | sort -V | tail'

alias rl='source ~/.zshrc'
alias n='nvim'

# LIST PATHS OF OTHER ZSH SHELLS I HAVE OPEN
lssh() {
	ps au \
		| awk '$11 == "-zsh" || $11 == "/bin/zsh" { print $2 }' \
		| xargs pwdx \
		| awk '{ print $2 }' \
		| sed -n "\|^${2}.*|p" \
		| sort -u \
		| nl
}

# CD TO SHELL NUMBER RETURNED BY LSSH
cdsh() {
	cd $(lssh \
		| sed "$1!d" \
		| cut -f 2)
}

# CD TO PATH OF ANOTHER SHELL, USING FZF AS SELECTOR
cs() {
	cmd1=$(lssh | fzf --select-1 --query "$1" --height=~50 | cut -f 2)
	cmd="cd $cmd1"
	print -S $cmd
	eval $cmd
}

# RUN THE COMMAND FROM HISTORY, USING FZF AS SELECTOR, ALTERNATIVE TO <C-R>
hf() {
	cmd=$(history 0 | sort -nr | cut -c 8- | fzf -e --select-1 --no-sort --query "$1" )
	# push the command into the history
	print -S $cmd
	eval $cmd
}

# REMMINA USING THE CONNECTION FILE SELECTED USING FZF
rf() {
	pushd ~/.local/share/remmina
	cmd=$(remmina -c $(ls $PWD/* | fzf -e --select-1 --no-sort --query "$1"))
	# push the command into the history
	print -S $cmd
	eval $cmd
	popd
}
alias clearswap='sudo swapoff -a && sudo swapon -a'
alias grep='grep --color=auto'
alias ls='ls --color=auto --group-directories-first'
alias la='ls -lAh --color=auto --group-directories-first'
alias timestamp='date +%Y-%m-%dT%H-%M-%S'

I use this function to launch GUI apps from the shell without occupying that shell or cluttering it with their output:

nown() {
        if [ -n "$1" ]
        then
                nohup $@ &> /dev/null & disown
        else
                echo "Don't give me a null command dumbass."
        fi
}

Not exactly an alias but a short script. First, get git-revise which is a replacement for git rebase, and fzf if for some reason you don't have it yet. Then make a script in your ~/.local/bin called git-f or whatever you'd like:

#!/bin/bash
REF=${1:-origin/main}  # adjust to your favorite trunk branch name
COMMIT=$(git log --pretty=oneline ${REF}.. \
         | fzf --preview "git show -p --stat {+1}" | cut -d' ' -f1)
if [ -n "$COMMIT" ]; then
    exec git revise "$COMMIT"
else
    exit 1
fi

Now hack away in a branch, make some commits, and at some point you will realize you want to modify an earlier commit. Use git add -p to add the relevant lines, but then instead of making a fixup commit just type git f and pick the target commit from the list.

alias upd=“yay -Syu --devel”

alias cleanup=“yay -Qdtq | yay -Rns-”

alias mirror=“sudo reflector --verbose --country ‘United States’ --protocol https --latest 15 --sort rate --save /etc/pacman.d/mirrorlist && sudo eos-rankmirrors”

alias et='emacsclient -ct'
alias ec='emacsclient -cn'
alias make='make --warn-undefined-variables'

alias clearswap='sudo swapoff -a && sudo swapon -a

alias reload='source ~/.bashrc'

scan_local() {

 local_ip=$(ip addr show wlan0 | grep "inet " | awk '{print $2}' | awk -F '/' '{print $1}')

 sudo nmap -sn "$local_ip/24"

}

Quite basic but saves me a couple of seconds each time. alias update="sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y"

TTIME (abbr - not alias)

abbr -a -- ttime date\ \'+It\ is\ \%-H\ \%M\ and\ \%S\ seconds\'\|espeak\ \>/dev/null\ 2\>/dev/null # imported from a universal variable, see `help abbr`

Interesting, git do support aliases too. "git st" etc What is .load.sh?

alias fuck='sudo $(fc -ln -1)'

Just use sudo !!

yeah, I could do that. Kinda prefer to use my alias anyway as the expletive is almost always the first word that comes to mind when I forget to sudo something

I always set these because I've been burned too many times:

Turn on interactive mode for dangerous commands

alias cp='cp -iv'
alias mv='mv -iv'
alias rm='rm -iv'
alias ein='f() { sudo emerge -av $1 };f'
alias eup='sudo emerge -avuDN @world'

The first alias actually gave me some ideas, thanks for that. But I don't understand how is what you did is really different from alias ein='sudo emerge -av'. I think the only thing that is different is the way you do it ein abc def will be the same as ein abc, but why would you want this?

I just realized what you were asking lol. I’ve had a couple beers, sorry.

Your idea may work, I’ll have to try it.

Selection of my fish abbreviations for comfy terminal creatures:

# MISC -----------------
abbr -a la 'exa -la'
abbr -a p 'python'
abbr -a v 'nvim'
abbr -a rmd 'rm -rf'
abbr -a feh 'feh --scale-down -d'
abbr -a ka 'doas killall'
abbr -a fp 'ffplay'
abbr -a ff 'firefox'
abbr -a tree 'exa -T'
abbr -a libver 'dpkg -l | grep'
abbr -a ex 'chmod +x'
# specific file and directory based
abbr -a notes 'nvim ~/.vimwiki/index.md'
abbr -a idir 'cd ~/some/important/dir'
abbr -a fishconf 'nvim ~/.config/fish/config.fish'
abbr -a vimconf 'nvim ~/.config/nvim/init.vim'
abbr -a i3conf 'nvim ~/.config/i3/config'
# PACMAN ---------------
abbr -a pin 'doas pacman -S'
abbr -a pun 'doas pacman -Rns'
abbr -a pss 'pacman -Ss'
abbr -a pls 'pacman -Qd'
abbr -a aurls 'paru -Qm'
abbr -a pct 'pacman -Q | wc -l'
abbr -a syu 'paru -Syu'
abbr -a pcl 'paccache -r -k 1; paru --cc;'
abbr -a pfd 'pacman -Qs'
# GIT ------------------
abbr -a ga 'git add -A; git status'
abbr -a gr 'git reset'
abbr -a gd 'git diff'
abbr -a gc 'git commit -m'
abbr -a gdc 'git diff HEAD~0 --stat'
abbr -a gl 'git log'
abbr -a gb 'git branch'
abbr -a gp 'git push origin'
abbr -a gch 'git checkout'
abbr -a gam 'git commit --amend - m'
abbr -a gcl 'git clone'
# RUST -----------------
abbr -a cc 'cargo clippy --all-features'
abbr -a ccc 'cargo check'
abbr -a cb 'cargo build'
abbr -a cr 'cargo run'
abbr -a cbr 'cargo build --release'
abbr -a crr 'cargo run --release'
abbr -a ct 'cargo test'
abbr -a ctt 'cargo tarpaulin --ignore-tests --skip-clean'
abbr -a bacon 'bacon clippy-all -w'
abbr -a cil 'cargo install --path ./'
abbr -a cia 'cargo install-update -a'
abbr -a ca 'cargo add'

I maybe steal your rust aliases What is bacon by the way?

Bacon is just compiler output but it "stays open" in your terminal and refreshes after you save your file; It is nice if you use something a bit minimal like vim without language server but you don't want to compile manually every time.

Parse JWT token which is base64 (alias is CSH syntax), usage: tokenparse filename

alias tokenparse "cat "\""\$1"\"" | jq -R 'split("\""."\"") | .[0],.[1] | @base64d | fromjson'"

Never worked with them but maybe helpful for the future.

*ahem

alias brb='paru -Syu --noconfirm && paru -Sc --noconfirm'

You should name it alias btw=... to fully embrace our stereotype ;).

alias gladog="git log —all —decorate —oneline —graph" is my all time favourite. Sometimes I just want to have a quick way to see the git graph in the terminal.

In case you don't know this give tig a try.

I didn’t. Thanks, I will have a look at it.

Uhhh a terminal git user too

Since my company won’t pay for Gitkraken I sadly am :/

I made a cool exercise some time ago: checking my top 10 used commands, to see how I can "optimize" them, and maybe create a few aliases to save a few keystrokes. Turns out I don't need that much aliases in the end:

alias v='vis' # my text editor
alias sv='doas vis'
alias ll='ls -l'

And that's pretty much it ^^ I do have a lot of scripts though, some of them being one-liners, but it makes them shell independent, which I like :)

For reference, here is my analysis of my top 10 most used commands.

edit: I do have a bunch of git aliases though for common subcommands I use. I prefer using them as git <alias> over using she'll specific aliases so I can always type "git" and not mentally think wether I need a git command or a shell alias.

Vis nether heard of this editor

Then you should definitely check it out: vis.

Its original goal was to be a vim clone with 90% of the features in 10% of the code. Then it grew into being the bastard son of Vim and Sam editors (plan9's structural regex based editor).

The result is vis, an editor with vim like navigation and text manipulation mechanics, but with access to Sam's powerful structural regex commands which works selection wise, rather than likewise like vim. Check this paper to learn about it: struct-regex.pdf.