Skip to content

Instantly share code, notes, and snippets.

@nakwa
Last active February 18, 2020 12:57
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 nakwa/09069ceba8d8ce59b2ced38d064c1563 to your computer and use it in GitHub Desktop.
Save nakwa/09069ceba8d8ce59b2ced38d064c1563 to your computer and use it in GitHub Desktop.
.profile stuff
# Source order:
# .zshenv → [.zprofile if login] → [.zshrc if interactive] → [.zlogin if login] → [.zlogout sometimes].
# ----------------------------------------------------- #
# PATH #
# ----------------------------------------------------- #
export PATH="$PATH:$GEM_HOME/bin"
export PATH="$PATH:$HOME/.cask/bin"
export PATH="$PATH:$HOME/.rvm/bin"
export PATH="$PATH:/usr/local/share/npm/bin"
# ----------------------------------------------------- #
# OpenSSL #
# ----------------------------------------------------- #
export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
# export PATH="/usr/local/opt/libressl/bin:$PATH"
# export LDFLAGS="-L/usr/local/opt/libressl/lib"
# export CPPFLAGS="-I/usr/local/opt/libressl/include"
# export PKG_CONFIG_PATH="/usr/local/opt/libressl/lib/pkgconfig"
# ----------------------------------------------------- #
# Locales #
# ----------------------------------------------------- #
export LC_ALL=en_US.UTF-8
# export LC_NUMERIC=en_F
# export LC_TIME=en_FR
# export LC_COLLATE=en_FR
# export LC_MONETARY=en_FR
# export LC_MESSAGES=en_FR
# ----------------------------------------------------- #
# NVM #
# ----------------------------------------------------- #
export NVM_DIR="/Users/[USER]/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# ----------------------------------------------------- #
# RVM #
# ----------------------------------------------------- #
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
# ----------------------------------------------------- #
# Env #
# ----------------------------------------------------- #
export PHP_AUTOCONF="/usr/local/bin/autoconf"
export GIT_PS1_SHOWDIRTYSTATE=1
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export VISUAL=emacs
export EDITOR="$VISUAL"
export GUI_EDITOR="sublime"
export EMAIL="[REDACTED]"
export GIT_COMMITTER_NAME="[REDACTED]"
export GIT_AUTHOR_NAME="[REDACTED]"
# ----------------------------------------------------- #
# Prompt #
# ----------------------------------------------------- #
parse_git_branch() {
branch="$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')"
if [ -n "$branch" ]; then
echo "(%{$fg[red]%}$branch%{$reset_color%})"
fi
}
PROMPT="%{$fg_bold[green]%}%n%{$reset_color%}:%{$fg_bold[blue]%}%~%{$reset_color%}\$(parse_git_branch)%(?:%{$fg[white]%}$%{$reset_color%}:%{$fg[grey]%}$%{$reset_color%}) "
# ----------------------------------------------------- #
# Core aliases #
# ----------------------------------------------------- #
alias gls='gls --color=auto --group-directories-first'
alias ll='gls -alF'
alias la='gls -alF'
alias l='gls -lF'
alias cd..='cd ..'
alias emacs='emacs -nw'
alias profile="$GUI_EDITOR ~/.profile"
alias edit="$GUI_EDITOR ."
alias ide="$GUI_EDITOR -a ."
alias reload=". ~/.profile"
# ----------------------------------------------------- #
# Functions #
# ----------------------------------------------------- #
who_use_this_port(){
lsof -n -i4TCP:$1 | grep LISTEN
}
uncompress_archive() {
tar -xvf $1
}
create_env_var_and_reload(){
export_name=$(echo $1 | cut -f1 -d=)
export_value=$(echo $1 | cut -f2- -d=)
if [ -n "$export_name" ]; then
echo "Set export [$export_name=$export_value] in .profile"
echo "export $export_name=\"$export_value\"" >> ~/.profile
source ~/.profile
fi
}
create_alias_and_reload(){
alias_name=$(echo $1 | cut -f1 -d=)
alias_value=$(echo $1 | cut -f2- -d=)
if [ -n "$alias_name" ]; then
echo "Set alias [$alias_name=$alias_value] in .profile"
echo "alias $alias_name=\"$alias_value\"" >> ~/.profile
source ~/.profile
fi
}
clean_logs() {
echo | find . -name '*.log'
find . -name '*.log' -type f -delete
}
clean_tree() {
echo | find . -name '.DS_Store'
find . -name '.DS_Store' -type f -delete
echo | find . -name '*~'
find . -name '*~' -type f -delete
echo | find . -name '#*#'
find . -name '#*#' -type f -delete
echo | find . -name 'desktop.ini'
find . -name 'desktop.ini' -type f -delete
echo | find . -name 'Thumbs.db'
find . -name 'Thumbs.db' -type f -delete
}
rename_with_exif() {
exiftool -P -d "%Y-%m-%d-%H%M%S" '-filename<${filemodifydate}_${BaseName}.%e' '-filename<${filemodifydate}_${make}_${BaseName}.%e' '-filename<${DateCreated}_${BaseName}.%e' '-filename<${DateCreated}_${make}_${BaseName}.%e' '-filename<${TrackCreateDate}_${BaseName}.%e' '-filename<${TrackCreateDate}_${make}_${BaseName}.%e' '-filename<${MediaCreateDate}_${BaseName}.%e' '-filename<${MediaCreateDate}_${make}_${BaseName}.%e' '-filename<${datetimeoriginal;}_${BaseName}.%e' '-filename<${datetimeoriginal;}_${make}_${BaseName}.%e' $1
}
find_file() {
find . -iname "*$1*" -type d -print | sed 's/^/"/;s/$/"/' | xargs -L1 stat -l -t '%FT %T'
find . -iname "*$1*" -type f -print | sed 's/^/"/;s/$/"/' | xargs -L1 stat -l -t '%FT %T'
}
find_in_file() {
grep -rnwl '.' -e "$1" 2>/dev/null
}
add_ssh_to_remote() {
cat ~/.ssh/id_rsa.pub | ssh $@ "(echo 'no' | ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa || true); cat >> ~/.ssh/authorized_keys"
}
alias searchall=find_in_file
alias search=find_file
alias setalias=create_alias_and_reload
alias setenv=create_env_var_and_reload
alias whouse=who_use_this_port
alias clean=clean_tree
alias cleanlogs=clean_logs
alias untar=uncompress_archive
alias enable-ssh=add_ssh_to_remote
# ----------------------------------------------------- #
# Dev helpers #
# ----------------------------------------------------- #
# PSQL
alias resetpsql="brew services restart postgresql"
# Kill it...: pg_ctl -D /usr/local/var/postgres stop -s -m fast
# Start it..: pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
# Other
alias npm-g="ls -la /usr/local/lib/node_modules/"
alias npm-rmg="npm ls -gp --depth=0 | awk -F/ '/node_modules/ && !/\/npm$/ {print $NF}' | xargs npm -g rm"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment