Skip to content

Instantly share code, notes, and snippets.

@Saakshaat
Last active May 25, 2021 15:22
Show Gist options
  • Save Saakshaat/787abe23941d0391c95d54af629226f1 to your computer and use it in GitHub Desktop.
Save Saakshaat/787abe23941d0391c95d54af629226f1 to your computer and use it in GitHub Desktop.
Shell Config and Alises

Since aliases created in terminal are only local to sessions, to make them permanent, you would have to write them in your system's ~/.bashrc file.

Open ~/.bashrc in your editor of choice:

vim ~/.bashrc

Simply write your commands (aliases/scripts) in this file, save [requires root permissions] and exit.

Now that your aliases are in this file, everytime you start a new session, all you'd have to do is load these all scripts/commands in this file using:

. ~/.bashrc

or

source ~/.bashrc

All aliases and scripts written in ~/.bashrcare now loaded and you can check that by writing alias in your terminal, which should list all available aliases.

To execute an alias/script, all you need to do is call it by its name and provide any rewuited params

leet
sheets
work dev

######################
This is my ZSH config which goes with iTerm and Powerlevel9K
######################
# 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/Apple1/.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="powerlevel9k/powerlevel9k"
# 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 $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.
# Caution: this setting can cause issues with multiline prompts (zsh 5.7.1 and newer seem to work)
# See https://github.com/ohmyzsh/ohmyzsh/issues/5765
# 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 $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)
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"
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon dir newline vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(battery load time)
POWERLEVEL9K_SHORTEN_STRATEGY=(truncate_to_last)
POWERLEVEL9K_TIME_FORMAT="%@"
POWERLEVEL9K_BATTERY_CHARGING_BACKGROUND="yellow"
POWERLEVEL9K_BATTERY_CHARGED_BACKGROUND="green"
POWERLEVEL9K_BATTERY_LOW_BACKGROUND="red"
POWERLEVEL9K_BATTERY_DISCONNECTED_BACKGROUND="blue"
POWERLEVEL9K_BATTERY_LOW_THRESHOLD=15
POWERLEVEL9K_BATTERY_VERBOSE=false
POWERLEVEL9K_BATTERY_ICON=''
POWERLEVEL9K_LOAD_NORMAL_BACKGROUND='192'
# auto-suggesstion stuff
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
#syntax-highlighting
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
plugins=(
zsh-autosuggestions
)
# Some system stuff
alias c="clear"
alias please='sudo'
alias cat="pygmentize -g"
del() {
rm -rf $1
}
# some aliases for applications
alias git_saak='open -a '\''Google Chrome'\'' https://github.com/Saakshaat' # opens my GitHub profile
alias leet='open -a '\''Google Chrome'\'' https://leetcode.com/' # opens leetcode so that I don't procrastinate over even opening it
alias sheets='open -a '\''Google Chrome'\'' https://sheets.google.com' # open google sheets; I don't want to slack off even before I start updating my financial tracker
alias spotify="osascript -e 'tell application "spotify" to play'" # start music on spotify
alias slack="open -a 'Slack'" # I want to read my team's updates with minimal mouse effort
# some common git commands
alias rep="git status"
alias b='git branch'
# create new branch
nb(){
git checkout -b $1
}
ch(){
git checkout $1
}
# add all files or all files (nested wherever) where the argument is a substring of the filename
ga(){
files=$( if [[ $1 == "" ]]; then echo "."; else echo "./*/$1*"; fi )
echo "Adding files: $files"
git add $files
}
# push changes to branch defined in first argument
push(){
current_branch=$(git symbolic-ref --short HEAD| pbcopy | pbpaste)
git push origin $( if [[ $1 == "" ]]; then echo $current_branch; else echo $1; fi )
}
# commit all tracked changes with the first argument as message
ca(){
git commit -am "$1"
}
# commit only the added changes with the first argument as message
cm(){
git commit -m "$1"
}
# check commit history upto $1
log() {
git log -$1
}
# I don't use the spotify alias described in the first file
# this script allows me to quit it when I start fearing tinnitus
# and restart it when, well you know
start() {
osascript -e 'tell application "spotify" to play'
osascript -e 'set Volume 1' # set the volume to optimal levels
}
quit() {
osascript -e 'quit application "spotify"'
echo Bye
}
restart() {
osascript -e 'quit application "spotify"'
echo 'Restarting'
sleep 1s && source spotify; start # the sleep command is used to wait the start before the quit is processed, else the start will be executed while/before quit
}
# utility to remove last downloaded file from Downloads utility
function ddel() {
file=`ls -t ~/Downloads | head -1`
echo Deleting $file...
rm -rf ~/"/Downloads/$file"
echo $file successfully deleted!
}
# small process to help me defocus from my screens
focus_helper() {
sleep 300; # timer for starting work
osascript -e 'display notification "It has been 15 minutes since you looked away" with title "Look Away!" sound name "Glass"';
sleep 300; # start next cycle of 15 minutes
osascript -e 'display notification "It has been 15 minutes since you looked away. 30 minutes since you started." with title "Look Away! Half way there." sound name "Glass"';
sleep 300; # at the 45 juncture now
osascript -e 'display notification "It has been 15 minutes since you looked away. 45 minutes since you started focusing." with title "Look Away! Another 15." sound name "Glass"';
sleep 300; # at the end of this, we would have completed 1 hour of work
osascript -e 'tell app "System Events" to display dialog "Way to go, Saakshaat!
You have been working non-stop for 1 hour. Time to take a short break. Walk around, stretch and relax your eyes before you sit down for work again."';
}
foc() {
if [[ $( jobs | grep -ni focus_helper ) == '' ]]; then
echo "Starting a new focus sessions. Have fun!"
nohup bash -c "source ~/.zshrc; focus_helper" &;
else
echo "Focus session already in progress."
fi
}
# I usually clone a remote branch from my work's git repo, everytime I start working on a feature
# This alias helps me clone and set up a specific branch from a repo locally
# you can either save this as an executable file or
# you can write this directly in your terminal
# to clone the `dev` branch from the 'example' repo (https://github.com/org/repo/)
# all I would have to write is work example dev
# This would have otherwise been `git clone -b dev --single-branch https://github.com/org/example/`
# the third argument can be used to define whether we want to clone this repo recursively
# Taking inspiration from this, we can modify this for whatever flags suit our needs
# cuts it all down, doesn't it 😉
work(){
repo=$1
branch=$( if [[ $2 == "" ]]; then echo master ; else echo $2; fi )
recursive=$( if [[ ${3:-} == "-r" ]]; then echo --recursive ; else echo ""; fi )
git clone -b $branch $recursive --single-branch https://github.com/org/$repo
}
# We use docker-compose for containerizing our applications, so here's some support for that
alias dcu="docker-compose up"
alias dcd="docker-compose down"
# sometime, we have to run test services whose files are marked as `docker-compose.test.yml`
# in these cases, docker-compose commands need to be provided a filename since these names deviate from
# the `docker-compose.yml` standard
# starting the services in `docker-compose.test.yml` would look like
# docker-compose -f docker-compose.test.yml up
# so our aliases cut it down to dtu docker-composer.test.yml
dtu(){
file=$( if [[ $1 == "" ]]; then echo docker-compose.test.yml ; else echo $1; fi )
docker-compose -f $file up
}
dtd(){
docker-compose -f $1 down
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment