Skip to content

Instantly share code, notes, and snippets.

@Jayashakthi28
Last active March 6, 2024 04:39
Show Gist options
  • Select an option

  • Save Jayashakthi28/1cc4c0532f060153b94d16b9136abe9c to your computer and use it in GitHub Desktop.

Select an option

Save Jayashakthi28/1cc4c0532f060153b94d16b9136abe9c to your computer and use it in GitHub Desktop.
#!/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*\""
# MacOS: Remove apps from quarantine
alias unquarantine="sudo xattr -rd com.apple.quarantine"
# 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
}
alias rug='run_all git'
# If you don't remember the branch name you want to checkout
# alias gcx="gco \$(git branch -a | sed -E 's/remotes\/([a-zA-Z-]*\/)//' | rg -v '\*|HEAD' | sort | uniq | fzf --select-1)"
# alias kbgc="keybase git gc --force vijay; keybase git gc --force profiles"
# shortcuts to handle multiple git repos
alias all="FOLDER=${HOME} MAXDEPTH=6 rug"
alias home="FOLDER=${HOME} FILTER=\"zsh|mise|tmux|vscod\" MAXDEPTH=6 rug"
alias tw="FOLDER=${HOME}/dev/tw MAXDEPTH=4 rug"
alias upreb="FOLDER=${HOME} FILTER=\"tmux|oss\" all upreb"
# utility functions
green() {
printf "\033[1;32m$1\033[0m"
}
red() {
printf "\033[31m$1\033[0m"
}
yellow() {
printf "\033[33m$1\033[0m"
}
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`)"
}
alias code-gist='code ~/dev ~/.zshrc ~/.zshrc.custom ~/.gitconfig* ~/.aliases ~/Brewfile ~/.zshenv ~/.zprofile ~/.zlogin ~/.p10k.zsh ~/.gitignore ~/.tool-versions ~/.vimrc ~/.envrc ~/.gemrc ~/.default-gems ~/${USERNAME}/profiles/.gitignore'
# install all plugins referenced in the mise config file ~/.tool-versions
# install_mise_plugins() {
# cat ${HOME}/.tool-versions | cut -d' ' -f1 | \grep "^[^\#]" | xargs -I{} mise plugin add {}
# }
install_mise_versions() {
find ${HOME} -name ".tool-versions" -maxdepth 4 -exec echo "===> Installing for {}" \; -execdir mise install \;
find ${HOME}/dev -name ".nvmrc" -maxdepth 4 -exec echo "===> Installing for {}" \; -execdir mise install \;
}
allow_all_direnv_configs() {
find ${HOME} -name ".envrc" -maxdepth 1 -exec echo "===> Registering for {}" \; -execdir direnv allow \;
find ${HOME}/dev -name ".envrc" -maxdepth 4 -exec echo "===> Registering for {}" \; -execdir direnv allow \;
}
# update_all_repos() {
# update-repo.sh ~/Personal/vijay/profiles; update-repo.sh ~
# }
# common build, debug and launch aliases for ferdium - converted to functions for lazy evaluation
# these will use the current folder name to find the shell script to run
launch_me() {
~/dev/launch-${PWD##*/}.sh
}
debug_me() {
~/dev/debug-${PWD##*/}.sh
}
build_me() {
~/dev/build-${PWD##*/}.sh
}
findrb() {
find . -iname "*.rb" -print0 | xargs -0 egrep -in --color "$@"
}
findyml() {
find . -iname "*.yml" -print0 | xargs -0 egrep -in --color "$@"
}
findrake() {
find . -iname "*.rake" -print0 | xargs -0 egrep -in --color "$@"
}
findhtmlerb() {
find . -iname "*.html.erb" -print0 | xargs -0 egrep -in --color "$@"
}
findjs() {
find . -iname "*.js*" -print0 | xargs -0 egrep -in --color "$@"
}
# 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 --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
alias c=clear
load_file_if_exists "${HOME}/.aliases.${USERNAME}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment