Skip to content

Instantly share code, notes, and snippets.

@vraravam
Last active April 18, 2024 09:17
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vraravam/ce0dda29bb07f0504df8686cfd2755ca to your computer and use it in GitHub Desktop.
Save vraravam/ce0dda29bb07f0504df8686cfd2755ca to your computer and use it in GitHub Desktop.
~/.aliases
#!/usr/bin/env zsh
# vim:syntax=zsh
# vim:filetype=zsh
# file location: ${HOME}/.aliases
# Add flags to existing aliases.
alias less="${aliases[less]:-less} -RF"
alias ls="${aliases[ls]:-ls} -G"
alias ll='ls -la'
alias cp="${aliases[cp]:-cp} -p"
alias grep="${aliases[grep]:-grep} -Hn --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.zsh_sessions,.zsh-evalcache,.zsh_evalcache,.IdentityService,.Trash} --exclude=\".*history\" --exclude=\".zcompdump*\""
# Uninstall and reinstall xcode (useful immediately after upgrade or if reinstalling the OS)
alias reinstall-xcode='rm -rf $(xcode-select -p) && xcode-select --install && xcodebuild -license accept'
alias reinstall-cmdline-tools='touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress && softwareupdate -ia && rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress && xcodebuild -license accept'
alias path='echo -e ${PATH//:/\\n}'
alias vi="vim"
alias ping="prettyping --nolegend"
alias cat='bat'
alias top='btop'
alias du="ncdu --color dark -r -x --exclude .git --exclude .svn --exclude node_modules --exclude .npm --exclude .nuget --exclude Library"
# Git commands
alias gco='git co'
# Note: Changed to a function so that it can accept parameters
st() {
git -C ${1:-.} st
}
# shortcuts to handle multiple git repos bypassing the omx auto-correct prompt
alias rug='run_all.sh git'
alias all="FOLDER=${HOME} MAXDEPTH=5 rug"
alias home="FOLDER=${HOME} FILTER=\"zsh|mise|tmux|vscod|rakshita\" MAXDEPTH=5 rug"
alias oss="FOLDER=${PROJECTS_BASE_DIR}/oss MAXDEPTH=2 rug"
alias tw="FOLDER=${PROJECTS_BASE_DIR}/tw MAXDEPTH=2 rug"
alias jd="FOLDER=${PROJECTS_BASE_DIR}/jd MAXDEPTH=3 rug"
alias upreb="FOLDER=${HOME} FILTER=\"tmux|oss\" all upreb"
# utility functions
blue() {
printf "\033[94m$1\033[0m"
}
cyan() {
printf "\033[96m$1\033[0m"
}
green() {
printf "\033[1;32m$1\033[0m"
}
red() {
printf "\033[31m$1\033[0m"
}
yellow() {
printf "\033[33m$1\033[0m"
}
warn() (
echo $(yellow "**WARN** $1")
)
if [[ "${OSTYPE}" =~ "darwin" ]]; then
# TODO: Remove later (kept here for reference): brew outdated --cask | xargs brew cask reinstall
alias bcg='brew outdated --greedy'
alias bcug='brew upgrade --greedy'
alias bupc='brew bundle check || brew bundle --all --cleanup; brew bundle cleanup -f; brew cleanup --prune=all; brew autoremove; brew upgrade'
fi
alias lstop='ls -Fhalts | head'
alias lstime='ls -Fhalts'
alias findbrokenlinks='find . -type l | (while read FN ; do test -e "$FN" || ls -ld "$FN"; done)'
alias clearlogs='rm -vrf */log/*.log'
alias clearcoverage='rm -vrf */coverage */coverage.data'
alias killds="sudo find . -name .DS_Store -exec rm -- {} +"
alias killloc="sudo find . -name .localized -exec rm -- {} +"
# Remove trailing spaces
if [[ "$(uname)" == "Linux" ]]; then
alias remove_trailing="find . -type f \( -name '*.*cs*' -o -name '*.*less' -o -name '*.*js*' -o -name '*.*rb' -o -name '*.*ml' -o -name '*.rake' -o -name '*.java' -o -name '*.ts*' \) -exec sed -i 's/[ ]*$//' {} \;"
fi
if [[ "$(uname)" == "MINGW32_NT-6.2" ]]; then
alias remove_trailing="find . -type f \( -name '*.*cs*' -o -name '*.*less' -o -name '*.*js*' -o -name '*.*rb' -o -name '*.*ml' -o -name '*.rake' -o -name '*.java' -o -name '*.ts*' \) -exec sed -i 's/[ ]*$//' {} \;"
fi
if [[ "${OSTYPE}" =~ "darwin" ]]; then
alias remove_trailing="find . -type f \( -name '*.*cs*' -o -name '*.*less' -o -name '*.*js*' -o -name '*.*rb' -o -name '*.*ml' -o -name '*.rake' -o -name '*.java' -o -name '*.ts*' \) -exec sed -i '' 's/[ ]*$//' {} \;"
fi
# generate mac addr to escape some free wifi mac addr restrictions
if [[ "$(uname)" == "Linux" ]]; then
alias free-wifi="(ifconfig eth0 | grep ether) && (openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' | xargs sudo ifconfig eth0 ether) && (ifconfig eth0 | grep ether)"
fi
if [[ "${OSTYPE}" =~ "darwin" ]]; then
# MacOS: Remove apps from quarantine
alias unquarantine="sudo xattr -rd com.apple.quarantine"
alias free-wifi="(ifconfig en0 | grep ether) && (openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' | xargs sudo ifconfig en0 ether) && (ifconfig en0 | grep ether)"
alias flush-dns="sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache;say MacOS DNS cache has been cleared"
fi
# Added to view the zsh startup time
time_zsh() {
shell=${1-$SHELL}
export IS_TIME_ZSH=1
for i in $(seq 1 10); do /usr/bin/time $shell -i -c exit; done
}
# Added to view the startup time for each of the zsh plugins
time_zsh_plugins() {
# Load all of the plugins that were defined in ${HOME}/.zshrc
for plugin ($plugins); do
timer=$(($(gdate +%s%N)/1000000))
load_file_if_exists "${ZSH_CUSTOM}/plugins/$plugin/$plugin.plugin.zsh" || load_file_if_exists "${ZSH}/plugins/$plugin/$plugin.plugin.zsh"
now=$(($(gdate +%s%N)/1000000))
elapsed=$(($now-$timer))
echo $elapsed":" $plugin
done
}
reals() {
ls -la "$(print `which $1`)"
}
# npm
alias npm_cleanup='npm cache clear --force'
# docker (TODO: Not sure why this is not done automatically by rancher when it starts up)
# alias start_docker="sudo ln -sf ${HOME}/.rd/docker.sock /var/run/docker.sock"
# alias stop_docker="sudo rm -rf /var/run/docker.sock"
alias docker_cleanup='docker system prune -a --volumes -f'
alias docker_list='docker ps -a && docker images'
# docker compose
alias dcup="docker-compose up --build --remove-orphans"
alias dcdn="docker-compose stop"
alias dcps="docker-compose ps"
# tmux
# alias tmn="tmux new-session -A -s"
# associate file extensions with applications
alias -s txt=code
alias -s log=code
load_file_if_exists "${HOME}/.aliases.${USERNAME}"
@vraravam
Copy link
Author

vraravam commented Feb 4, 2024

Moved aliases that were specific to my prefs into a different file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment