Skip to content

Instantly share code, notes, and snippets.

@jalasem
Created January 30, 2020 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jalasem/1ff60f3033d9e226b06c9f5e278bd2e8 to your computer and use it in GitHub Desktop.
Save jalasem/1ff60f3033d9e226b06c9f5e278bd2e8 to your computer and use it in GitHub Desktop.
zsh config script
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/jalasem/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="agnoster"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# 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 automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true
# 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.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# 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?
# Standard 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)
#plugins=(
# git
# zsh-autosuggestions
# zsh-syntax-highlighting
# bundler
# dotenv
# osx
# rake
# rbenv
# ruby
#)
source $ZSH/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# 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"
# 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 zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# Configuring Our Prompt
# ======================
# if you install git via homebrew, or install the bash autocompletion via homebrew, you get __git_ps1 which you can use in the PS1
# to display the git branch. it's supposedly a bit faster and cleaner than manually parsing through sed. i dont' know if you care
# enough to change it
# This function is called in your prompt to output your active git branch.
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
# This function builds your prompt. It is called below
function prompt {
# Define the prompt character ♥ <- original promp characater colored red
local CHAR="👨🏽‍💻🔥🚀" #Where creating a local variable called CHAR that takes in ascii but its 2018 we can use unicode emojis
# Define some local color variables.
local RED="\[\e[0;31m\]"
local BLUE="\[\e[0;34m\]"
local GREEN="\[\e[0;32m\]"
local GRAY_TEXT_BLUE_BACKGROUND="\[\e[37;44;1m\]"
# Define a variable to reset the text color you have to place this after the text where you want your color to end.
local RESET="\[\e[0m\]"
#using ls color to colorize directories and files check man lscolors for how this works
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
# ♥ ☆ - Keeping some cool ASCII Characters for reference <-- UNICODE its 2018
# Here is where we actually export the PS1 Variable which stores the text for your prompt
export PS1="\[\e]2;\u@\h\a[$GRAY_TEXT_BLUE_BACKGROUND\t$RESET]$RED\$(parse_git_branch) $GREEN\W\n$BLUE//$RED $CHAR $RESET"
PS2='🤔 > ' #PS1 and PS2 are your prompts. You will hit PS2 if you ever type a command and the shell is expecting more. Like if you just type a quote '"' followed bythe return key it would expect the closing quote on the next line.
PS4='+ '
} #our function ends here
# Finally call the function and our prompt is all pretty
function shortcuts {
local BOLDRED="\e[01;31m" # Hashes are comments what the stuff to the left of this does is create a local variable called BOLDRED that we can later call with $BOLDRED
local ENDCOLOR="\e[0m" #Local variable to reset the color
printf " Better LS\n" #printf is just a print command similar to echo but it allows for text formatting.
printf " alias l='ls -lah'\n" #l will replace having to type ls -lah into the terminal. We will set that alias in another function.
printf " Git Shortcuts Common Terminal Commands \n"
printf "===================================================================\n"
printf "$BOLDRED gcl$ENDCOLOR ='git clone' |pwd = print working directory\n"
printf "$BOLDRED gst$ENDCOLOR ='git status' |mkdir = creates directory\n"
printf "$BOLDRED gl $ENDCOLOR ='git pull' |cp = copy directory \n"
printf "$BOLDRED gp $ENDCOLOR ='git push' |touch = creates file \n"
printf "$BOLDRED gd $ENDCOLOR ='git diff | subl' |man = manual pages \n"
printf "$BOLDRED gc $ENDCOLOR ='git commit -v' |less = opposite of more :) \n"
printf "$BOLDRED gca$ENDCOLOR ='git commit -v -a' |cd = change directory \n"
printf "$BOLDRED gb $ENDCOLOR ='git branch' |vi = text editor \n"
printf "$BOLDRED gba$ENDCOLOR ='git branch -a' |nano = quick terminal text editor \n"
printf "$BOLDRED gcam$ENDCOLOR='git commit -am' |mv = move file to another directory \n"
printf "$BOLDRED gbb$ENDCOLOR ='git branch -b' |rm = remove a file or directory with -r\n"
sleep .3 #Sleep creates some time before executing the next line.
printf "\nType$BOLDRED shortcuts$ENDCOLOR anytime\n"
printf "for a list of these shortcuts\n"
sleep .2
printf "\nFor a list of directory shortcuts\n"
printf "type$BOLDRED dir$ENDCOLOR like in windows\n"
sleep .05
printf "\nFor the weather type $BOLDRED\n"
printf "weather$ENDCOLOR followed by your city name\n" #The weather fucntion will be set in another function
}
# prompt
# shortcuts
function dir { #this is just a function to show you what director shortcuts are available to you. If you add more functions you will remind yourself about those functions here.
local BOLDRED="\e[01;31m"
local ENDCOLOR="\e[0m"
printf "$BOLDRED desk$ENDCOLOR takes you to your desktop\n"
printf "$BOLDRED home$ENDCOLOR takes you to the root of your home directory\n"
printf "$BOLDRED workspace$ENDCOLOR takes you to your workspace directory\n"
printf "$BOLDRED verse$ENDCOLOR takes you to your microverse directory\n"
}
# Creates a project with an index.html and a style.css
function project {
if [ -d ~/workspace/projects ]
then
mkdir ~/workspace/projects/$1
touch ~/workspace/projects/$1/index.html
touch ~/workspace/projects/$1/style.css
touch ~/workspace/projects/$1/index.js
html >> ~/workspace/projects/$1/index.html
cd ~/workspace/projects/$1
else
mkdir ~/workspace/projects
mkdir ~/workspace/projects/$1
touch ~/workspace/projects/$1/index.html
touch ~/workspace/projects/$1/style.css
html $1 >> ~/workspace/projects/$1/index.html
cd ~/workspace/projects/$1
fi
}
#Helower function for project function above.
function html {
echo "<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">
<link rel=\"stylesheet\" href=\"style.css\">
<script src=\"index.js\"></script>
<title>$1</title>
</head>
<body>
</body>
</html>"
}
function desk { #this function will allow you to get to your desktop directory just by typing desk
cd /Users/$USER/Desktop/$@
}
function workspace { #change this path to your workspace folder. Anything after $USER starts from your home folder.
cd /Users/$USER/workspace/$@
}
function nairaworks { #change this path to your nairaworks folder. Anything after $USER starts from your home folder.
cd /Users/$USER/workspace/fluidangle/clients/nairaworks/$@
}
function fclients { #change this path to your fluidangle clients folder. Anything after $USER starts from your home folder.
cd /Users/$USER/workspace/fluidangle/clients/$@
}
function verse { #change this path to your development folder. Anything after $USER starts from your home folder.
cd /Users/$USER/verse/$@
}
function home {
cd /Users/$USER/$@
}
function sandbox {
cd /Users/$USER/sandbox/$@
}
function weather { #Get the weather. Service provided by @igor_chubin
curl wttr.in/${@:-<YOURZIPORLOCATION>}
#@igor_chubin on twitter or https://github.com/chubin/wttr.in
} #type weather followed by your city or airport code to get an awesome weather display right on your terminal.< // 😎 Weather NYC >
# For more prompt coolness, check out Halloween Bash:
# http://xta.github.io/HalloweenBash/
# If you break your prompt, just delete the last thing you did.
# And that's why it's good to keep your dotfiles in git too.
# A handy function to open your bash profile from any directory
function bp {
$EDITOR ~/.bash_profile
}
# A handy function to open your zshell profile from any directory
function zp {
$EDITOR ~/.zshrc
}
# Environment Variables
# =====================
# Library Paths
# These variables tell your shell where they can find certain
# required libraries so other programs can reliably call the variable name
# instead of a hardcoded path.
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
export VISUAL="code"
export SVN_EDITOR="code"
export GIT_EDITOR="vim"
export EDITOR="code"
# Helpful Functions
# =====================
# A function to CD into the desktop from anywhere
# so you just type desktop.
# HINT: It uses the built in USER variable to know your OS X username
# USE: desktop
# desktop subfolder
# create a python virtual environment
function penv3 {
python3 -m venv ~/.virtualenvs/$1
}
# create a python virtual environment
function penv2 {
python2 -m venv ~/.virtualenvs/$1
}
# get a list of all your python environments
function penv {
ls -lrt -d -1 ~/.virtualenvs/*
}
# uses a python virtual environment
function penvuse {
source ~/.virtualenvs/$1/bin/activate
}
# A function to easily grep for a matching process
# USE: psg postgres
function psg {
FIRST=`echo $1 | sed -e 's/^\(.\).*/\1/'`
REST=`echo $1 | sed -e 's/^.\(.*\)/\1/'`
ps aux | grep "[$FIRST]$REST"
}
# function to easily kill process on specified port number
# USE: kport 5000
function kport {
kill lsof -t -i :$1
}
# A function to extract correctly any archive based on extension
# USE: extract imazip.zip
# extract imatar.tar
function extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Aliases
# =====================
# LS
alias l='ls -lah'
# Git
alias gcl="git clone"
alias gst="git status"
alias gl="git pull"
alias gp="git push"
alias gd="git diff | subl"
alias gc="git commit -v"
alias gca="git commit -v -a"
alias gb="git branch"
alias gba="git branch -a"
alias gbb="git branch -b"
alias d="cd /Users/$USER/Desktop"
alias showfiles='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app'
alias hidefiles='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app'
alias zshconfig="mate ~/.zshrc"
alias ohmyzsh="mate ~/.oh-my-zsh"
alias code="code-insiders"
alias aws="aws2"
# Case-Insensitive Auto Completion
# bind "set completion-ignore-case on"
source /Users/jalasem/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment