Skip to content

Instantly share code, notes, and snippets.

@yosukehasumi
Last active November 24, 2022 03:41
Show Gist options
  • Save yosukehasumi/fb5c97f661ee3d4e1b41049707606fb5 to your computer and use it in GitHub Desktop.
Save yosukehasumi/fb5c97f661ee3d4e1b41049707606fb5 to your computer and use it in GitHub Desktop.
my_bash
#!/usr/bin/env bash
export CLICOLOR=1
export TERM=xterm-256color
export BASH_SILENCE_DEPRECATION_WARNING=1
# PS1
export PS1="________________________________________________________________________________\n| \w \n| => "
export PS2="| => "
# Set default editor
export EDITOR='code -w'
# Shortcut for Chinuk Toolchain
tt () { toolchain "$@"; }
# Preferred 'cp' implementation
alias cp='cp -iv'
# Preferred 'mv' implementation
alias mv='mv -iv'
# Preferred 'mkdir' implementation
alias mkdir='mkdir -pv'
# Create the directory if it doesn't exist before making the file
touchp() { mkdir -p $(dirname "$1") && > "$1"; }
# Preferred 'ls' implementation
alias ll='ls -FGlAhp'
# Preferred 'less' implementation
alias less='less -FSRXc'
# Always list directory contents upon 'cd'
cd() { builtin cd "$@"; ll; }
# Go back 1 directory level (for fast typers)
alias cd..='cd ../'
# Go back n directory level
alias ..='cd ../'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'
alias ......='cd ../../../../../'
alias .......='cd ../../../../../../'
# edit: Opens any file in sublime editor
alias edit='subl'
# f: Opens current directory in MacOS Finder
alias f='open -a Finder ./'
# ~: Go Home
alias ~="cd ~"
# which: Find executables
alias which='type -all'
# path: Echo all executable Paths
alias path='echo -e ${PATH//:/\\n}'
# Show_options: display bash options settings
alias show_options='shopt'
# trash: Moves a file to the MacOS trash
trash () { command mv "$@" ~/.Trash ; }
# ql: Opens any file in MacOS Quicklook Preview
ql () { qlmanage -p "$*" >& /dev/null; }
# lr: Full Recursive Directory Listing
alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'' | less'
# ff: Find file under the current directory
ff () { /usr/bin/find . -name "$@" ; }
# extract: Extract most know archives with one command
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# findPid: find out the pid of a specified process
findPid () { lsof -t -c "$@" ; }
pid () { ps -ef | grep $@ ;}
# myip: Public facing IP Address
alias myip='curl http://www.myip4.com'
# cleanupDS: Recursively delete .DS_Store files
alias cleanupDS="find . -type f -name '*.DS_Store' -ls -delete"
# finderShowHidden: Show hidden files in Finder
alias finderShowHidden='defaults write com.apple.finder ShowAllFiles TRUE'
# finderHideHidden: Hide hidden files in Finder
alias finderHideHidden='defaults write com.apple.finder ShowAllFiles FALSE'
# start php server in current directory
alias phpServer='php -S localhost:5000'
# Ruby Testing
t () {
if [ $2 ] ; then
ruby -I lib:test "$1" -n "$2";
else
ruby -I lib:test "$1";
fi
}
# bundle exec rake task
brake () { bundle exec rake "$1"; }
# Load brew path
export PATH=/usr/local/bin:$PATH
eval "$(/opt/homebrew/bin/brew shellenv)"
# Load [email protected]
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/[email protected]/lib/pkgconfig"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/homebrew/opt/[email protected]"
# Load rbenv automatically
eval "$(rbenv init -)"
# NVM
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# export NVM_DIR="$HOME/.nvm"
# [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
# [ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
# Docker
alias dockerPurgeSystem='docker system prune -f'
alias dockerPurgeVolumes='docker volume prune -f;'
alias dockerPurgeImages='docker stop $(docker ps -a -q); docker rm $(docker ps -a -q); docker rmi $(docker images -q);;'
alias dockerPurgeAll='docker stop $(docker ps -a -q); docker rm $(docker ps -a -q); docker rmi $(docker images -q); docker volume prune -f; docker system prune -f'
alias dockerStop='docker stop $(docker ps -a -q)'
# Load ssh key
# ssh-add -K ~/.ssh/id_rsa
# Scratch
alias scratch.md='subl ~/Desktop/scratch.markdown'
alias scratch.sql='subl ~/Desktop/scratch.sql'
alias scratch.rb='subl ~/Desktop/scratch.rb'
alias scratch.sh='subl ~/Desktop/scratch.sh'
# Flush DNS
alias flushDNS='sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache'
# show ssh config
alias sshconfig='cat ~/.ssh/config'
export PATH="/opt/homebrew/opt/libressl/bin:$PATH"
export PATH="/opt/homebrew/opt/postgresql@12/bin:$PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment