Skip to content

Instantly share code, notes, and snippets.

@DorkNstein
Last active May 4, 2023 00:50
Show Gist options
  • Save DorkNstein/dbb6b7aad85590d53ae47371826bb7b6 to your computer and use it in GitHub Desktop.
Save DorkNstein/dbb6b7aad85590d53ae47371826bb7b6 to your computer and use it in GitHub Desktop.
# More symbols to choose from
# ☀ ✹ ☄ ♆ ♀ ♁ ♐ ♇ ♈ ♉ ♚ ♛ ♜ ♝ ♞ ♟ ♠ ♣ ⚢ ⚲ ⚳ ⚴ ⚥ ⚤ ⚦ ⚒ ⚑ ⚐ ♺ ♻ ♼ ☰ ☱ ☲ ☳ ☴ ☵ ☶ ☷
# ✡ ✔ ✖ ✚ ✱ ✤ ✦ ❤ ➜ ➟ ➼ ✂ ✎ ✐ ⨀ ⨁ ⨂ ⨍ ⨎ ⨏ ⨷ ⩚ ⩛ ⩡ ⩱ ⩲ ⩵ ⩶ ⨠
# ⬅ ⬆ ⬇ ⬈ ⬉ ⬊ ⬋ ⬒ ⬓ ⬔ ⬕ ⬖ ⬗ ⬘ ⬙ ⬟ ⬤ 〒 ǀ ǁ ǂ ĭ Ť Ŧ ᐅ
local ret_status="%(?:%{$fg_bold[green]%}➜%{$fg_bold[yellow]%}%!:%{$fg_bold[green]%}➜%{$fg_bold[red]%}%!)"
PROMPT='%{$fg_bold[cyan]%}%c%{$reset_color%} $(git_time_since_commit)$(git_prompt_trucated_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[magenta]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%}✚"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%} ✂"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%} ✔"
# Colors vary depending on time lapsed.
ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}"
ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}"
ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[yellow]%}"
ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%}✚"
ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[blue]%}✹"
ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%}✖"
ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[magenta]%}➜"
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[yellow]%}═"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[cyan]%}✭"
ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg_bold[red]%}‹"
ZSH_THEME_RUBY_PROMPT_SUFFIX="›%{$reset_color%}"
# local time, color coded by last return code
time_enabled="%(?.%{$fg[yellow]%}.%{$fg[red]%})%*%{$reset_color%}"
time_disabled="%{$fg[yellow]%}%*%{$reset_color%}"
time=$time_enabled
# Determine the time since last commit. If branch is clean,
# use a neutral color, otherwise colors will vary according to time.
function git_time_since_commit() {
if git rev-parse --git-dir > /dev/null 2>&1; then
# Only proceed if there is actually a commit.
if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
# Get the last commit.
last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
now=`date +%s`
seconds_since_last_commit=$((now-last_commit))
# Totals
MINUTES=$((seconds_since_last_commit / 60))
HOURS=$((seconds_since_last_commit/3600))
# Sub-hours and sub-minutes
DAYS=$((seconds_since_last_commit / 86400))
SUB_HOURS=$((HOURS % 24))
SUB_MINUTES=$((MINUTES % 60))
if [[ -n $(git status -s 2> /dev/null) ]]; then
if [ "$MINUTES" -gt 30 ]; then
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
elif [ "$MINUTES" -gt 10 ]; then
COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
else
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
fi
else
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
fi
if [ "$HOURS" -gt 24 ]; then
echo "$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}| "
elif [ "$MINUTES" -gt 60 ]; then
echo "$COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}| "
else
echo "$COLOR${MINUTES}m%{$reset_color%}| "
fi
else
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
echo "$COLOR~|"
fi
fi
}
function my_git_prompt() {
tester=$(git rev-parse --git-dir 2> /dev/null) || return
INDEX=$(git status --porcelain 2> /dev/null)
STATUS=""
# is branch ahead?
if $(echo "$(git log origin/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
fi
# is branch behind?
if $(echo "$(git log HEAD..origin/$(git_current_branch) 2> /dev/null)" | grep '^commit' &> /dev/null); then
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_BEHIND"
fi
# is anything staged?
if $(echo "$INDEX" | command grep -E -e '^(D[ M]|[MARC][ MD]) ' &> /dev/null); then
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_STAGED"
fi
# is anything unstaged?
if $(echo "$INDEX" | command grep -E -e '^[ MARC][MD] ' &> /dev/null); then
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED"
fi
# is anything untracked?
if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED"
fi
# is anything unmerged?
if $(echo "$INDEX" | command grep -E -e '^(A[AU]|D[DU]|U[ADU]) ' &> /dev/null); then
STATUS="$STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED"
fi
if [[ -n $STATUS ]]; then
STATUS=" $STATUS"
fi
echo "$STATUS"
}
function git_prompt_trucated_info() {
if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
ref="$(command echo ${ref#refs/heads/})"
length=${#ref}
maxLength=$(command git config --get oh-my-zsh.max-branch-length 2>/dev/null)
if [[ -z ${maxLength} ]]; then
maxLength=20
fi
if [[ ${length} -gt ${maxLength} ]]; then
regex=$(command git config --get oh-my-zsh.prefix-regex 2>/dev/null)
if [[ -n ${regex} ]]; then
ref=$(command echo ${ref} | sed "s/${regex}//1" ) #${regex})
fi
prefixLength=$(command git config --get oh-my-zsh.prefix-length 2>/dev/null)
if [[ -z ${prefixLength} ]]; then
prefixLength=0
fi
if [[ ${prefixLength} -gt 0 ]]; then
prefix=$(command echo ${ref} | cut -c ${prefixLength})
ref=$(command echo ${ref} | cut -c `expr ${prefixLength} + 1`-)
length=${#ref}
fi
fi
if [[ ${length} -gt ${maxLength} ]]; then
suffixLength=$(command git config --get oh-my-zsh.suffix-length 2>/dev/null)
if [[ -z ${suffixLength} ]]; then
suffixLength=0
fi
length=${#ref}
suffixStart=`expr ${length} - ${suffixLength} + 1`
separatorLength=3 #3 dots...
nameEnd=`expr ${maxLength} - ${suffixLength} - ${separatorLength}`
ref="$(command echo ${ref} | cut -c 1-${nameEnd})...$(command echo ${ref} | cut -c ${suffixStart}-)"
fi
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref}$(my_git_prompt)$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
}
# export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin:/opt/homebrew/bin
# Path to your oh-my-zsh installation.
export ZSH=/Users/ymalekar/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME=dorknstein
# K8s auto-complete
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git node npm nvm brew extract z web-search wakeonlan Xcode xcode copyfile cp vscode)
# Path to your oh-my-zsh installation.
source $ZSH/oh-my-zsh.sh
# User configuration
# export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin"
export PATH=$PATH:/opt/homebrew/bin
export PATH="/usr/local/share/zsh/functions:$PATH"
export PATH="$PATH:/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin"
export PATH=$PATH:/Users/ymalekar/Documents
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# ssh
# export SSH_KEY_PATH="~/.ssh/dsa_id"
#################### Functions ########################
gitcomp() {
gaa && gcmsg $1 && gp
}
gblist() {for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch; done | sort -r}
gdtag() {
git push --delete origin $1
git tag -d $1
}
gatag() {
git tag -a $1 -m "$2"
git push origin --tags
}
ltree() {
exa --tree --level=$1 --ignore-glob="node_modules|build" .
}
chromeappmode(){
# /Applications/Google\ Chrome.app -a --app=$1
open -a "Google Chrome" "$1";
}
edgeappmode(){
open -na "Google Chrome" --args -incognito "$1";
}
##########################################################
#################### Aliases ########################
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
alias clr="reset"
alias z="code ~/.zshrc"
alias zs="source ~/.zshrc"
alias ll="exa -l --git"
alias nvmsrc="source ~/.nvm/nvm.sh"
alias wifi="osx-wifi-cli"
alias lv="live-server"
alias lvq="live-server -q"
alias localhttpsServer="ngrok http 3002"
alias appmode=chromeappmode
alias weather="ansiweather -l Dallas,US -u metric -s true -f 7 -d true"
alias omz="code ~/.oh-my-zsh"
alias bashprofile="code ~/.bash_profile"
alias f="open ~/Desktop/"
alias c="cd ~/Desktop/"
alias fp="open ~/Desktop/projects/"
alias cp="cd ~/Desktop/projects/"
alias gdiff="git diff --color | diff-so-fancy"
alias gdmc="git diff --name-only --diff-filter=U"
# Project commands
export HOME_BASE="/Users/ymalekar" # Change this to your home directory
export PROJECT_BASE="${HOME_BASE}/Desktop/projects" # Change this to your projects directory
export MS_BASE="${PROJECT_BASE}/microsoft" # Change this to your projects directory
export T2_CONF_BASE="${HOME_BASE}/Library/Containers/com.microsoft.teams2/Data/Library/Application\ Support/Microsoft/MSTeams" # Teams2 config directory
export LOCAL_URL="https://local.teams.office.com/v2" # Teams local url
export T2_URL="https://teams.microsoft.com/v2" # Teams v2 url
alias cpers="cd ${PROJECT_BASE}/personal" # cd to personal directory
alias cnext="cd ${PROJECT_BASE}/personal/nextjs-learn"
alias fms="open ${MS_BASE}"
alias cms="cd ${MS_BASE}"
alias ctmp="cd ${MS_BASE}/tmp"
alias ctsw="cd ${MS_BASE}/tsw"
alias csandbox="cd ${MS_BASE}/sandbox"
alias cinsp="cd ${MS_BASE}/sandbox/nikhanch/CdlTrafficInspector"
alias tmprun="ctmp && yarn start:fast react-web-client" # Run Local Teams
alias tflrun="ctmp && yarn start:fast react-web-client --flavor=life" # Run Local Teams with Life
alias tmprfast="ctmp && yarn fast && tmprun" # Run Local Teams with Fast Build
alias mastersync="git fetch && gco master && git pull" # Sync master branch
alias setup="mastersync && tmprfast" # Sync master branch and run local teams
alias gmm="git merge master" # Merge master branch
alias tmpmw="ctmp && yarn start:fast multi-window" # Run Local Teams with Multi Window
alias tmpmwport="ctmp && yarn start:fast multi-window --port=8080" # Run Local Teams with Multi Window on port 8080
alias ydoc="ctmp && yarn doctor" # Run yarn doctor
alias ct2conf="cd ${T2_CONF_BASE}" # cd to Teams2 config directory
alias lteams="chromeappmode ${LOCAL_URL}" # Open Local Teams in Chrome
alias pteams="chromeappmode ${LOCAL_URL}" # Open Local Teams in Chrome
alias tmpcov="sh ${MS_BASE}/tmp.coverage.sh" # Run test coverage report
kusto() {
chromeappmode https://dev.azure.com/domoreexp/Teamspace/_wiki/wikis/Teamspace.wiki/31244/Working-with-Kusto
edgeappmode https://dataexplorer.azure.com/
}
t1test() {
yarn test:e2e:cookiejar --appType='enterprise' --productIteration=T1 --mockAuthentication=false --suiteName=Nx --mockServices=true --runInBand --config tools/build/jest/cookiejar/jest.config.js --platforms=edgeBrowser --automationFramework=Playwright --nativeShellRing=ring0 --nativeShellEnv=prod --baseUrl=https://teams.microsoft.com/ $1
}
t2test() {
yarn test:e2e:cookiejar --appType='enterprise' --productIteration=T2 --mockAuthentication=true --suiteName=Nx --mockServices=true --runInBand --config tools/build/jest/cookiejar/jest.config.js --platforms=edgeBrowser --automationFramework=Playwright --nativeShellRing=ring0 --nativeShellEnv=prod --baseUrl=${LOCAL_URL} $1
}
t2testdesk() {
yarn test:e2e:cookiejar --appType='enterprise' --productIteration=T2 --mockAuthentication=true --suiteName=Nx --mockServices=true --runInBand --config tools/build/jest/cookiejar/jest.config.js --platforms=edgeMaglev --teamsAppLocation='existing' --nativeShellRing=ring0 --nativeShellEnv=prod --baseUrl=${LOCAL_URL} $1
}
t2updateconfig() {
ct2conf
echo "\033[0;33mOpening T2.1 config..."
code configuration.json
if [ $# -eq 0 ]; then
else
echo $1 > configuration.json
fi
ctmp
}
t2ctn() {
if [ $# -eq 0 ]; then
t2updateconfig
return
fi
echo "\033[0;33mSetting container to $1..."
if [ $1 = "local" ]; then
t2updateconfig '{"core/startPage": "'${LOCAL_URL}'?ring=ring0&skipauthstrap=1","core/devMenuEnabled": true,"core/cookieKeyValues": "{\"VGVzdENvb2tpZQ==\":\"ODQwOTM1MzctY2VmZS00ZGY0LWE0ZDMtMjI3NDNiMDQxMjMy\", \"VGVhbXNSaW5n\":\"cmluZzA=\"}","core/localStorageKeyValues": "{\"bG9jYWxEZWJ1Zw\": \"dHJ1ZQ\",\"dG1wLnNldHRpbmdz\":\"ewogICJhdXRoIjogewogICAgImVuYWJsZUxvZ291dFYyIjogdHJ1ZSwKICAgICJlbmFibGVMb2dvdXRBY2NvdW50U3dpdGNoIjogdHJ1ZQogIH0sCiAgImNvcmUiOiB7CiAgICAiZW5hYmxlTVRNQSI6IHRydWUsCiAgICAiZGlzYWJsZUV4cGVyaWVuY2UiOiBmYWxzZQogIH0KfQ==\"}"}'
elif [ $1 = "clean" ]; then
t2updateconfig '{}'
else
t2updateconfig '{"core/startPage":"'${T2_URL}'/?skipauthstrap=1&ring=ring0&container='$1'","core/devMenuEnabled": true}'
fi
echo "\033[0;32mSet container to $1"
}
alias t2conf="t2ctn"
alias t2local="t2ctn local"
alias t2clean="t2ctn clean"
##########################################################
####################### ZSH RPrompt ###########################
# Shows execution time for each command on the right side of the terminal
function preexec() {
timer=${timer:-$SECONDS}
}
function precmd() {
if [ $timer ]; then
timer_show=$(($SECONDS - $timer))
export RPROMPT="%F{cyan}${timer_show}s %{$reset_color%}"
unset timer
fi
}
##################################################
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
source ${NVM_DIR}/nvm.sh # This loads nvm
eval "$(mcfly init zsh)" # McFly history search
antigen theme ~/.oh-my-zsh/themes/ dorknstein
antigen bundle zsh-users/zsh-completions # useful completion scripts
antigen bundle zsh-users/zsh-autosuggestions # autosuggestions
antigen bundle zsh-users/zsh-syntax-highlighting # syntax highlighting
antigen bundle zsh-users/zsh-history-substring-search # history search
antigen bundle command-not-found # provides feedback on commands based on cache of existing programs.
antigen bundle djui/alias-tips # help remember aliases
# antigen bundle unixorn/autoupdate-antigen.zshplugin # auto update plugins
antigen apply
######################## TORUS ###############################
# source ~/.zprofile TorusClient='export DYLD_FALLBACK_LIBRARY_PATH="/Library/Scripts/Torus/Mac/lib:/lib:/usr/local/lib:/usr/lib:";/usr/local/bin/pwsh -NoLogo -NoExit -File /Library/Scripts/Torus/TorusClient.ps1'
# alias TorusClientSudo='export DYLD_FALLBACK_LIBRARY_PATH="/Library/Scripts/Torus/Mac/lib:/lib:/usr/local/lib:/usr/lib:";sudo /usr/local/bin/pwsh -NoLogo -NoExit -File /Library/Scripts/Torus/TorusClient.ps1'
# alias torus='export DYLD_FALLBACK_LIBRARY_PATH="/Library/Scripts/Torus/Mac/lib:/lib:/usr/local/lib:/usr/lib:";/usr/local/bin/pwsh -NoLogo -NoExit -File /Library/Scripts/Torus/TorusClient.ps1'
alias TorusClient='export DYLD_FALLBACK_LIBRARY_PATH="/Library/Scripts/Torus/Mac/lib:/lib:/usr/local/lib:/usr/lib:";/usr/local/bin/pwsh -NoLogo -NoExit -File /Library/Scripts/Torus/TorusClient.ps1'
alias TorusClientSudo='export DYLD_FALLBACK_LIBRARY_PATH="/Library/Scripts/Torus/Mac/lib:/lib:/usr/local/lib:/usr/lib:";sudo /usr/local/bin/pwsh -NoLogo -NoExit -File /Library/Scripts/Torus/TorusClient.ps1'
alias torus='export DYLD_FALLBACK_LIBRARY_PATH="/Library/Scripts/Torus/Mac/lib:/lib:/usr/local/lib:/usr/lib:";/usr/local/bin/pwsh -NoLogo -NoExit -File /Library/Scripts/Torus/TorusClient.ps1'
################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment