Last active
September 26, 2024 08:04
-
-
Save kunagpal/dc1dd731b7698fc7590a0e2681e9eaed to your computer and use it in GitHub Desktop.
Bash heaven
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add `~/bin` to the `$PATH` | |
export BUN_INSTALL="$HOME/.bun"; | |
export PATH="$HOME/bin:$BUN_INSTALL/bin:$PATH:$HOME/go/bin"; | |
# Set PATH, MANPATH, etc., for Homebrew. | |
eval "$(/opt/homebrew/bin/brew shellenv)"; | |
# Load the shell dotfiles, and then some: | |
# * ~/.path can be used to extend `$PATH`. | |
# * ~/.extra can be used for other settings you don’t want to commit. | |
for file in ~/.{path,bash_prompt,exports,aliases,functions,extra}; do | |
[ -r "$file" ] && [ -f "$file" ] && source "$file"; | |
done; | |
unset file; | |
# Case-insensitive globbing (used in pathname expansion) | |
shopt -s nocaseglob; | |
# Append to the Bash history file, rather than overwriting it | |
shopt -s histappend; | |
# Autocorrect typos in path names when using `cd` | |
shopt -s cdspell; | |
# Enable some Bash 4 features when possible: | |
# * `autocd`, e.g. `**/qux` will enter `./foo/bar/baz/qux` | |
# * Recursive globbing, e.g. `echo **/*.txt` | |
for option in autocd globstar; do | |
shopt -s "$option" 2> /dev/null; | |
done; | |
# Add tab completion for many Bash commands | |
if which brew &> /dev/null && [ -f "$(brew --prefix)/share/bash-completion/bash_completion" ]; then | |
source "$(brew --prefix)/share/bash-completion/bash_completion"; | |
elif [ -f /etc/bash_completion ]; then | |
source /etc/bash_completion; | |
fi; | |
# Enable tab completion for `g` by marking it as an alias for `git` | |
if type _git &> /dev/null && [ -f /usr/local/etc/bash_completion.d/git-completion.bash ]; then | |
complete -o default -o nospace -F _git g; | |
fi; | |
complete -o default -F __start_kubectl k | |
# Add tab completion for SSH hostnames based on ~/.ssh/config, ignoring wildcards | |
[ -e "$HOME/.ssh/config" ] && complete -o "default" -o "nospace" -W "$(grep "^Host" ~/.ssh/config | grep -v "[?*]" | cut -d " " -f2- | tr ' ' '\n')" scp sftp ssh; | |
# Add tab completion for `defaults read|write NSGlobalDomain` | |
# You could just use `-g` instead, but I like being explicit | |
complete -W "NSGlobalDomain" defaults; | |
# Add `killall` tab completion for common apps | |
complete -o "nospace" -W "Contacts Calendar Dock Finder Mail Safari iTunes SystemUIServer Terminal Twitter" killall; | |
alias c='clear' | |
alias ws='webstorm' | |
alias vim='nvim' | |
alias vi='nvim' | |
alias k='kubectl' | |
alias nano='nvim' | |
alias db='mysql -uroot' | |
alias list='ps aux | grep' | |
alias me='cd ~/Code/GitHub' | |
alias i='brew install' | |
alias work='cd ~/Code/Postman' | |
alias ins='brew install' | |
alias u='HOMEBREW_NO_ENV_HINTS=TRUE brew update && brew upgrade' | |
alias gpgrs='gpgconf --kill gpg-agent' | |
alias dns='dig +nocmd any +multiline +noall +answer' | |
alias gar='git archive' | |
alias gcl='git clone' | |
alias gcg='git config' | |
alias gi='git init' | |
alias grs='git reset' | |
alias grm='git rm' | |
alias gs='git status' | |
alias gcb='git checkout -b' | |
alias ga='git add' | |
alias gd='git diff' | |
alias gds='git diff --stat' | |
alias gf='git fetch --all' | |
alias gs='git status' | |
alias gr='git remote' | |
alias gc='git add . && git commit -S -m' | |
alias gct='git add . && git commit -S -m "temp"' | |
alias gu='git checkout develop && git pull origin --prune' | |
alias gab='git reset HEAD~1 && git add . && git commit -S -m "temp"' | |
alias gb='git branch' | |
alias gl='git log --graph --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset" --abbrev-commit' | |
alias gm='git merge --no-ff -S' | |
alias gp='git push -u' | |
alias gpl='git pull' | |
alias gbd='git branch -D' | |
alias gre='git reset' | |
alias gt='git tag' | |
alias gcd='git checkout develop' | |
alias gco='git checkout' | |
alias gcf='git checkout -f' | |
alias bi='bun install --exact' | |
alias ni='npm install' | |
alias bif='bun install --force' | |
alias nif='npm install --force' | |
alias bid='bun install --dev --exact' | |
alias nis='npm install --save' | |
alias nid='npm install --save-dev' | |
alias big='bun install --global' | |
alias nig='sudo npm install --global' | |
alias nr='npm run' | |
alias br='bun run' | |
alias ns='npm show' | |
alias na='npm run archive' | |
alias np='npm run package' | |
alias nt='npm test' | |
alias bt='bun run test' | |
alias bic='rm -rf node_modules && bun install' | |
alias nic='rm -rf node_modules && npm install --force' | |
alias nu='npm update' | |
alias ncu='npm-check -u' | |
alias mocha='node $(npm bin)/mocha' | |
alias sails='node $(npm bin)/sails' | |
alias pm2='node $(npm bin)/pm2' | |
alias eslint='node $(npm bin)/eslint' | |
alias yankee='node $(npm bin)/yankee' | |
[ -f $(brew --prefix)/etc/bash_completion ] && . $(brew --prefix)/etc/bash_completion | |
[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash | |
__git_complete ga _git_add | |
__git_complete gb _git_branch | |
__git_complete gco _git_checkout | |
__git_complete gcl _git_clone | |
__git_complete gf _git_fetch | |
__git_complete gl _git_log | |
__git_complete gm _git_merge | |
__git_complete gpl _git_pull | |
__git_complete gp _git_push | |
__git_complete gr _git_remote | |
__git_complete gre _git_reset | |
__git_complete grm _git_rm | |
__git_complete gs _git_status | |
__git_complete gt _git_tag | |
work() { | |
cd ~/Code/Postman/$1; | |
} | |
gcp() { | |
git add .; | |
git commit -S -m "$1"; | |
git push -u; | |
} | |
gta() { | |
git tag -s v$1 -m "$2"; | |
} | |
gnf() { | |
git checkout -b feature/$1; | |
} | |
#gcl() { | |
# TARGET=$1; | |
# Handle plain repositories | |
# if [[ $TARGET ]]; then | |
# fi | |
# github org suffix present | |
# git protocol prefix | |
# fully qualified git URIs | |
# git clone $TARGET ${2:-~/Code/Postman/}; # $2 is an optional clone location | |
#} | |
aws_login() { | |
BLUE='\033[0;34m'; | |
NO_COLOUR='\033[0m'; | |
PROFILE=${1:-default}; | |
REGION=${2:-us-east-1}; | |
IDENTITY=$(aws sts get-caller-identity --profile $PROFILE); | |
ACCOUNT=$(echo $IDENTITY | jq -r '.Account'); | |
USER_ID=$(echo $IDENTITY | jq -r '.Arn' | sed 's/:user\//:mfa\//'); | |
read -p "$(echo -e "$BLUE Enter MFA code for $USER_ID ($PROFILE):$NO_COLOUR ")" MFA_CODE; | |
CREDS=$(aws sts get-session-token --profile $PROFILE --serial-number $USER_ID --token-code $MFA_CODE | jq '.Credentials'); | |
[[ -z ${CREDS} ]] && exit 1; | |
export AWS_ACCESS_KEY_ID=$(echo ${CREDS} | jq -r '.AccessKeyId'); | |
export AWS_SECRET_ACCESS_KEY=$(echo ${CREDS} | jq -r '.SecretAccessKey'); | |
export AWS_SESSION_TOKEN=$(echo ${CREDS} | jq -r '.SessionToken'); | |
[[ $(which docker) ]] && aws ecr get-login-password --region $REGION | docker login --username AWS --password-stdin $ACCOUNT.dkr.ecr.$REGION.amazonaws.com; | |
} | |
rel() { | |
# Ensure that the provided version is in valid semver format | |
if [[ ! $1 =~ ^v?[0-9]+(\.[0-9]+){2}(-[a-z]+\.\d+)?$ ]]; then | |
echo "A valid semver must be provided as the first argument to ${FUNCNAME[0]}"; | |
exit 1; | |
fi | |
ver=${1/v/}; # Strip the leading v from the version (if it exists) | |
msg=$2; | |
[[ -z $msg ]] && msg="Released v${ver}"; | |
# Update the master branch to the latest | |
git checkout master; | |
git pull origin master; | |
# Update develop to the latest, and create a release brach off of it. | |
git checkout develop; | |
git pull origin develop; | |
git checkout -b release/$ver; | |
# Bump version in package.json, but do not create a git tag | |
npm version $ver --no-git-tag-version; | |
# Inject the current release version and date into the CHANGELOG file | |
sed -i "" "3i\\ | |
#### v${ver} (`date '+%d %B %Y'`)\\ | |
\\ | |
" CHANGELOG.md; | |
# Find all commits between the HEAD on develop and the latest tag on master, and pipe their messages into the clipboard | |
git log $(git describe --tags master --abbrev=0)..HEAD --merges --pretty=format:'* %s' | pbcopy; | |
# Provision manual intervention for CHANGELOG.md | |
vi CHANGELOG.md; | |
# Create the release | |
git add CHANGELOG.md package.json; | |
[[ -f package-lock.json ]] && git add package-lock.json; | |
git commit -S -m "$msg"; | |
# Merge the release branch into develop and push | |
git checkout develop; | |
git merge --no-edit --no-ff -S release/$ver; | |
git push origin develop; | |
# Merge the release branch into master, create a tag and push | |
git checkout master; | |
git merge --no-edit --no-ff -S release/$ver; | |
git tag -s "v$ver" -m "$msg"; | |
git push origin master --follow-tags; | |
# Move back to develop | |
git checkout develop; | |
git branch -d release/$ver; | |
unset msg ver; | |
} | |
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH" | |
source <(kubectl completion bash) | |
. "$HOME/.cargo/env" | |
export N_PREFIX="$HOME/n"; [[ :$PATH: == *":$N_PREFIX/bin:"* ]] || PATH+=":$N_PREFIX/bin" # Added by n-install (see http://git.io/n-install-repo). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Shell prompt based on the Solarized Dark theme. | |
# Screenshot: http://i.imgur.com/EkEtphC.png | |
# Heavily inspired by @necolas’s prompt: https://github.com/necolas/dotfiles | |
# iTerm → Profiles → Text → use 13pt Monaco with 1.1 vertical spacing. | |
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then | |
export TERM='gnome-256color'; | |
elif infocmp xterm-256color >/dev/null 2>&1; then | |
export TERM='xterm-256color'; | |
fi; | |
prompt_git() { | |
local s=''; | |
local branchName=''; | |
# Check if the current directory is in a Git repository. | |
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ]; then | |
# check if the current directory is in .git before running git checks | |
if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]; then | |
# Ensure the index is up to date. | |
git update-index --really-refresh -q &>/dev/null; | |
# Check for uncommitted changes in the index. | |
if ! $(git diff --quiet --ignore-submodules --cached); then | |
s+='+'; | |
fi; | |
# Check for unstaged changes. | |
if ! $(git diff-files --quiet --ignore-submodules --); then | |
s+='!'; | |
fi; | |
# Check for untracked files. | |
if [ -n "$(git ls-files --others --exclude-standard)" ]; then | |
s+='?'; | |
fi; | |
# Check for stashed files. | |
if $(git rev-parse --verify refs/stash &>/dev/null); then | |
s+='$'; | |
fi; | |
fi; | |
# Get the short symbolic ref. | |
# If HEAD isn’t a symbolic ref, get the short SHA for the latest commit | |
# Otherwise, just give up. | |
branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \ | |
git rev-parse --short HEAD 2> /dev/null || \ | |
echo '(unknown)')"; | |
[ -n "${s}" ] && s=" [${s}]"; | |
echo -e "${1}${branchName}${2}${s}"; | |
else | |
return; | |
fi; | |
} | |
if tput setaf 1 &> /dev/null; then | |
tput sgr0; # reset colors | |
bold=$(tput bold); | |
reset=$(tput sgr0); | |
# Solarized colors, taken from http://git.io/solarized-colors. | |
black=$(tput setaf 0); | |
blue=$(tput setaf 33); | |
cyan=$(tput setaf 37); | |
green=$(tput setaf 64); | |
orange=$(tput setaf 166); | |
purple=$(tput setaf 125); | |
red=$(tput setaf 124); | |
violet=$(tput setaf 61); | |
white=$(tput setaf 15); | |
yellow=$(tput setaf 136); | |
else | |
bold=''; | |
reset="\e[0m"; | |
black="\e[1;30m"; | |
blue="\e[1;34m"; | |
cyan="\e[1;36m"; | |
green="\e[1;32m"; | |
orange="\e[1;33m"; | |
purple="\e[1;35m"; | |
red="\e[1;31m"; | |
violet="\e[1;35m"; | |
white="\e[1;37m"; | |
yellow="\e[1;33m"; | |
fi; | |
# Highlight the user name when logged in as root. | |
if [[ "${USER}" == "root" ]]; then | |
userStyle="${red}"; | |
else | |
userStyle="${orange}"; | |
fi; | |
# Highlight the hostname when connected via SSH. | |
if [[ "${SSH_TTY}" ]]; then | |
hostStyle="${bold}${red}"; | |
else | |
hostStyle="${yellow}"; | |
fi; | |
# Set the terminal title and prompt. | |
PS1="\[\033]0;\W\007\]"; # working directory base name | |
PS1+="\[${bold}\]\n"; # newline | |
PS1+="\[${userStyle}\]\u"; # username | |
PS1+="\[${white}\] at "; | |
PS1+="\[${hostStyle}\]\h"; # host | |
PS1+="\[${white}\] in "; | |
PS1+="\[${green}\]\w"; # working directory full path | |
PS1+="\$(prompt_git \"\[${white}\] on \[${violet}\]\" \"\[${blue}\]\")"; # Git repository details | |
PS1+="\n"; | |
PS1+="\[${white}\]\$ \[${reset}\]"; # `$` (and reset color) | |
export PS1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Insane work! 🔥