Ask HN: What are the best things in your shell config? Functions, aliases, etc.
What are the most useful/essential things in your shell configuration file. Be it custom function, wrappers, aliases, etc. Please provide an explanation since it isn't always obvious to others. I have a couple of favorites (bash): I always alias rm, mv, cp, ln to -i. Also, gt, gtt, gl, ga, gc, gu, gp, gd, gd2 for git status -s, status, log, add, commit, pull, push, diff, diff to rev. All with useful (to me) flags. My prompt looks like this: I have `git fsync` which pulls and deletes all the local branches when the remote branch is deleted. alias bat=cat
alias frep=grep and i'm good to gp
`CDPATH` is great. It's like having z, j or zoxide installed for configurable paths. While it doesn't fully replace the former, it provides a lot of the useful functionality for me. # Only provide CDPATH when interactive...
if [[ $- = *i* ]];
then
export CDPATH=:"$HOME"/Projects/
fi
There are certain files that get created from various apps that I run that aren't really useful (font caches, etc). Try as I might, I can't get them into appropriate XDG-style locations. I could wrap them in boxxy, but this seems simpler. I put them in the trash in case something blew up and I need to recover it. _cleanup_files() {
# Cleanup files
local OFFENDERS=(
"$HOME"/.java
"$HOME"/.oracle_jre_usage
"$HOME"/.pki
"$HOME"/.wget-hsts
"$HOME"/.xsession-errors
...
)
for FILE in "${OFFENDERS[@]}";
do
if [[ -e "$FILE" ]];
then
trash-put "$FILE"
fi
done
}
# Prompt
export PROMPT_COMMAND=_cleanup_files
So that I see where I am, all commands line up, the last status is obvious and also there’s never this: \n
[<status>] user@site [<cwd>]\n
$
My .inputrc always contains https://stackoverflow.com/a/1030206 $ cat nonewline.txt
Oops no newline$ _
This is probably my most-used alias on my machine, by far. fsync = !git pull --rebase && git fetch -p && git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D