Files
profile/.rc.d/aliases.sh

132 lines
5.4 KiB
Bash
Executable File

# Helper: define alias only if command doesn't already exist
ensure_alias() {
local name="$1" cmd="$2"
if ! command -v "$name" >/dev/null 2>&1; then
alias "$name"="$cmd"
fi
}
# Detect WSL
is_wsl=false
if grep -qi microsoft /proc/version 2>/dev/null; then
is_wsl=true
fi
# TODO: detect color support and enable/disable color in aliases based on that.
# File Manipulation
# TODO: bash ls doesn't need -G or maybe macs don't. Figure that out and use that test here.
alias ls='ls -G --color=auto'
alias lsd='ls -G --color=auto -d'
alias ll='ls -G --color=auto -l'
alias lld='ls -G --color=auto -l -d'
alias lsg='ls | grep --color'
alias llg='ls -l| grep --color'
#alias ln='ln -ivw'
alias ln='ln -iv'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias slash='ls -SlAhr'
alias slasher='ls -SlAh'
alias slashed='ls -SlAhrd'
alias ds='function f() { du -h -d 1 $* | sort -h | tee ~/dirsize ; unset -f f; }; f'
alias dud='function { du -h -d 1 $* | sort -h }'
alias dud='function f() { du -h -d 1 "$@" 2>/dev/null | sort -h ; unset -f f; }; f'
alias dudr='function { du -h -d 1 $* | sort -h -r }'
alias dudr='function f() { du -h -d 1 "$@" 2>/dev/null | sort -h -r ; unset -f f; }; f'
alias mvn='mv -n'
alias gmv='mv $* ~/Google\ Drive/My\ Drive/'
alias gmvn='mv -n $* ~/Google\ Drive/My\ Drive/'
alias omv='mv $* ~/OneDrive/'
alias omvn='mv -n $* ~/OneDrive/'
alias mv='mv -i'
alias rm='rm -i'
alias rs='rsync -avhz --progress'
alias rsfat='rs --no-perms --no-owner --no-group --no-times'
alias md=mkdir
alias rd=rmdir
# Git shortcuts
alias it=git
alias rsgit='rsync -avhz --no-perms --exclude='\''.git'\'' --exclude='\''.vscode'\'
# Bazel shortcuts
alias refresh_bazel='bazel run @hedron_compile_commands//:refresh_all'
alias bb='bazel build //...'
alias bt='bazel test //...'
alias bq='bazel query //...'
alias br='bazel run @hedron_compile_commands//:refresh_all'
alias cbb='clear && bazel build //...'
alias cbt='clear && bazel test //...'
alias cbq='clear && bazel query //...'
# Utilities
alias iwyu='include-what-you-use'
alias show-android-emulators="ps aux | head -n 1 && ps aux | grep avd | sed '$d'"
alias kill-all-android-emulators='adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done'
alias freespace="df -I -h -T nodevfs | grep -i -v -E '/\.timemachine/|/System/Volumes/|/com\.apple\.TimeMachine\.localsnapshots/' | sed -e 's/ / /g'"
alias fs="df -I -h -T nodevfs | grep -i -v -E '/\.timemachine/|/System/Volumes/|/com\.apple\.TimeMachine\.localsnapshots/' | sed -e 's/ / /g'"
alias hashes='md5deep -r'
# Mac equivalent of lsusb on linux
alias lsusb='system_profiler SPUSBDataType'
alias tea='tee -a'
alias find_recent='function { find . $* -exec ls -ltr {} + }'
alias find_recent='function f() { find . $* -exec ls -ltr {} + ; unset -f f; }; f'
# pbcopy
if ! command -v pbcopy >/dev/null 2>&1; then
if command -v wl-copy >/dev/null 2>&1; then
ensure_alias pbcopy 'wl-copy'
elif command -v xclip >/dev/null 2>&1; then
ensure_alias pbcopy 'xclip -selection clipboard'
elif [ "$is_wsl" = true ] && command -v clip.exe >/dev/null 2>&1; then
ensure_alias pbcopy 'clip.exe'
fi
fi
# pbpaste
if ! command -v pbpaste >/dev/null 2>&1; then
if command -v wl-paste >/dev/null 2>&1; then
ensure_alias pbpaste 'wl-paste'
elif command -v xclip >/dev/null 2>&1; then
ensure_alias pbpaste 'xclip -selection clipboard -o'
elif [ "$is_wsl" = true ] && command -v powershell.exe >/dev/null 2>&1; then
ensure_alias pbpaste 'powershell.exe -noprofile Get-Clipboard'
fi
fi
# In Development
# Dosn't work if command is piped e.g. `log_and_do "ls | tee out.txt" my_other_file.txt`
# or stdout is redirected e.g. `log_and_do "ls > out.txt" my_other_file.txt`
alias log_and_do='function { `echo "# $1 >> $2\n" > $2 && echo $1` >> $2 }'
# This should get the PIDs of any avd commands running and kill-9 them and then do the
# same as kill-all-android-emulators to clean them up after.
# alias kaae="kill -9 `ps aux | grep avd | sed '$d' | cut -f 2 -w` > /dev/null"
# TODO: Stuff I don't know why other configs setup
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
#alias ll='ls -alF'
#alias la='ls -A'
#alias l='ls -CF'
# From Bash on Ubuntu
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
#alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# WSL Specific
#alias pbcopy=clip.exe
#alias pbpaste="powershell.exe -noprofile Get-Clipboard"
# SSH-Agent setup
# alias sshgo='eval $(ssh-agent -s) && ssh-add ~/.ssh/id_ed25519 ~/.ssh/id_rsa ~/.ssh/id_win_ed25519 ~/.ssh/id_win_rsa'
alias sshgo='eval $(ssh-agent -s) && for key in ~/.ssh/id_*; do [[ -f "$key" && "${key##*/}" != *.* ]] && ssh-add "$key"; done'
alias inspect-video='mediainfo --Inform="Video;Codec: %Format%\nProfile: %Format_Profile%\nResolution: %Width%x%Height%\nBitrate: %BitRate/String%\nBitrate mode: %BitRate_Mode%\nFrame rate: %FrameRate% fps\n"'
alias wget-rip='wget --page-requisites --convert-links --adjust-extension --no-clobber --span-hosts'
alias wget-rip='wget --page-requisites --convert-links --adjust-extension --no-clobber --span-hosts -r -l1'
alias wget-rip-lite='wget --page-requisites --convert-links --adjust-extension --no-clobber --span-hosts -r -l1 -A jpg,jpeg,png,gif,html,css,ttf,otf'