What are the best, most useful aliases or functions etc for bash that you've collected or written? Or bash scripts. Please give explanation/usage if necessary. Ones you actually use often. Thanks!
Ask HN: Best things in your bash_profile/aliases?
1–10 of 288 posts
Re: Ask HN: Best things in your bash_profile/aliases?
#2I use my git aliases dozens of times each day, especially the last few that pop open relevant repository webpages: https://github.com/andjosh/dotfiles/blob/master/.gitconfig#L...
Re: Ask HN: Best things in your bash_profile/aliases?
#3Since I'm working in git repos the majority of the time, I type these hundreds of times per day:
alias s="git status"
alias d="git diff"
I prefer looking at this stuff in a terminal rather than an IDE. Reducing them to a single character just feels so good. Note: not a git alias like "git s", literally just the single character "s" in Bash itself.And coming in third:
alias ..="cd .."Re: Ask HN: Best things in your bash_profile/aliases?
#4 alias v="nvim"Re: Ask HN: Best things in your bash_profile/aliases?
#5My most commonly used thing in my profile is this combination git tag, push, and npm publish using the current version in my package.json file:
np() {
PACKAGE_VERSION=$(node -p -e "require('./package.json').version")
SHORTVER="v$PACKAGE_VERSION"
LONGVER="Version $PACKAGE_VERSION"
echo $LONGVER
git tag -a "$SHORTVER" -m "$LONGVER" && git push --tags && npm publish
}Re: Ask HN: Best things in your bash_profile/aliases?
#6 alias search='set -f;search';search() { find . ${2:+-name "$2"} -type f -print0 | xargs -0 grep --color=auto "$1"; }
Recursively searches the files in the current directory for string matches. You can optionally provide a second glob argument to restrict what files to search. This is basically a dumber version of ack-grep, but I wrote it before I learned about ack.Re: Ask HN: Best things in your bash_profile/aliases?
#7 alias ll='ls -l'Re: Ask HN: Best things in your bash_profile/aliases?
#8[deleted]
Re: Ask HN: Best things in your bash_profile/aliases?
#9I have 'usb' aliased as my main USB's directory.
Making 'cd' more explicit:
cd ( ) {
builtin cd "$@"
echo "$OLDPWD -> $PWD"
}
Up directory alias ..='cd ../'
This one I use to find bits in my favourite books/essays, which I have in folders in /books, under e.g. /books/Shakespeare/Macbeth, then search with 'book to be or' etc. book () {
# Find occurrences of words in texts. Put folders in ~/books, or soft links (ln -s)
# Displays only complete words found, not parts of words.
GREP_COLOR=red
grep -r -n -i --word-regexp --color -C 1 "$*" ./books/
echo `grep -r -i "$*" ./books/ | wc -l` occurrences of \"$*\" found, `grep -i -r --word-regexp "$*" ./books/ | wc -l` as a whole word.
}
'dlm' downloads mp4 file from URL in clipboard #!/bin/bash
#dlm - download mp4 from clipboard URL. usage: 'dlm myfile' downloads myfile.mp4
#with resume after 5 secs until finish.
fname=$(pbpaste)
echo "Download $fname as $1.mp4 : "
until curl -C - -kLo $1.mp4 "$fname"
do
sleep 5
doneRe: Ask HN: Best things in your bash_profile/aliases?
#10alias lcoate=locate
alias ll="ls -l"
alias ..="cd .."
alias ...="cd ../.."
alias mdd='mkdir $(date -I)'
alias cdd='cd $(date -I)'
alias xt="xtermset -T "
alias dtail="dmesg|tail"