Skip to content

Instantly share code, notes, and snippets.

@nhuanhoangduc
Last active June 26, 2024 09:39
Show Gist options
  • Save nhuanhoangduc/8814b4313a7903ea0bb7af477cf56529 to your computer and use it in GitHub Desktop.
Save nhuanhoangduc/8814b4313a7903ea0bb7af477cf56529 to your computer and use it in GitHub Desktop.
Command aliases
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
cdnvm() {
command cd "$@";
nvm_path=$(nvm_find_up .nvmrc | tr -d '\n')
# If there are no .nvmrc file, use the default nvm version
if [[ ! $nvm_path = *[^[:space:]]* ]]; then
declare default_version;
default_version=$(nvm version default);
# If there is no default version, set it to `node`
# This will use the latest version on your machine
if [[ $default_version == "N/A" ]]; then
nvm alias default node;
default_version=$(nvm version default);
fi
# If the current version is not the default version, set it to use the default version
if [[ $(nvm current) != "$default_version" ]]; then
nvm use default;
fi
elif [[ -s $nvm_path/.nvmrc && -r $nvm_path/.nvmrc ]]; then
declare nvm_version
nvm_version=$(<"$nvm_path"/.nvmrc)
declare locally_resolved_nvm_version
# `nvm ls` will check all locally-available versions
# If there are multiple matching versions, take the latest one
# Remove the `->` and `*` characters and spaces
# `locally_resolved_nvm_version` will be `N/A` if no local versions are found
locally_resolved_nvm_version=$(nvm ls --no-colors "$nvm_version" | tail -1 | tr -d '\->*' | tr -d '[:space:]')
# If it is not already installed, install it
# `nvm install` will implicitly use the newly-installed version
if [[ "$locally_resolved_nvm_version" == "N/A" ]]; then
nvm install "$nvm_version";
elif [[ $(nvm current) != "$locally_resolved_nvm_version" ]]; then
nvm use "$nvm_version";
fi
fi
}
alias cd='cdnvm'
cd "$PWD"
# Git
alias g='git'
alias ga='git add'
alias gm='git commit'
alias gp='git push origin HEAD'
alias gbk='git add . && git commit -nm "[skip ci] bk" && git push origin HEAD'
# Docker
alias d='docker'
alias dc='docker compose'
alias dl='docker compose logs -f --tail 100'
# Kubectl
alias k='kubectl'
# get
alias kg='kubectl get'
alias kgp='kubectl get pod'
alias kgs='kubectl get service'
alias kgd='kubectl get deployment'
alias kgi='kubectl get ingress'
alias kgn='kubectl get node'
# log
alias kl='kubectl logs -f'
# describe
alias kdes='kubectl describe'
alias kdesp='kubectl describe pod'
alias kdess='kubectl describe service'
alias kdesd='kubectl describe deployment'
alias kdesi='kubectl describe ingress'
alias kdesn='kubectl describe node'
# delete
alias kdel='kubectl delete'
alias kdelp='kubectl delete pod'
alias kdels='kubectl delete service'
alias kdeld='kubectl delete deployment'
alias kdeli='kubectl delete ingress'
alias kdeln='kubectl delete node'
alias amo-ssh='ssh -i ~/Documents/aws_t2_medium.pem'
# Fedora
alias clearcache="sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'"
export MONGOMS_DOWNLOAD_URL=https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-4.4.15.tgz
export MONGOMS_DOWNLOAD_URL=https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse15-4.4.15.tgz
export PATH=/usr/bin:$PATH
export DOCKER_HOST=unix:///run/user/1000/docker.sock
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$PATH:$JAVA_HOME/bin
export GIT_SSH_COMMAND='ssh -i /home/nhuan/.ssh/nhuan -o IdentitiesOnly=yes'
ms() {
export GIT_SSH_COMMAND='ssh -i /home/nhuan/.ssh/ms -o IdentitiesOnly=yes'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment