diff --git a/.bashlocal-example b/.bashlocal-example index 987c192..d6166ce 100644 --- a/.bashlocal-example +++ b/.bashlocal-example @@ -1,6 +1,6 @@ -#! /bin/bash +# -*- mode: sh-script; -*- -# Set up ssh-agent +# SSH Option 1: Vanilla ssh-agent {{{ if [ -z "$(pgrep ssh-agent)" ]; then rm -rf /tmp/ssh-* eval $(ssh-agent -s) > /dev/null @@ -9,32 +9,43 @@ else export SSH_AUTH_SOCK=$(find /tmp/ssh-* -name agent.*) fi -if [ -f ~/.ssh/hesaam_github -a `ssh-add -l | grep -c hesaam_github` -eq 0 ]; then - ssh-add ~/.ssh/hesaam_github +# if ssh into this machine, and you don't have ssh-agent this prints garbage warn +if [ -f ~/.ssh/id_ed25519 -a `ssh-add -l | grep -c id_ed25519` -eq 0 ]; then + ssh-add ~/.ssh/id_ed25519 fi +# }}} -[ -f ~/.fzf.bash ] && source ~/.fzf.bash +# SSH Option 2: Keychain {{{ +eval $(keychain --eval --agents ssh id_ed25519 2>/dev/null) +# }}} -export iceWork="$HOME/work" -export wWork="$iceWork" +# 2600Hz Dirs {{{ +export wKazoo="${wWork}/2600hz" +export KAZOO_SRC="${wKazoo}/kazoo-master" +export DOCKER_ROOT="${wWork}/dockerfiles/kazoo/composer/docker" +export KZ_DOCKER_ROOT="${wWork}/dockerfiles/kazoo/composer/docker" -if [ x"$PLATFORM" = x"Microsoft" ]; then - export wHomeWinPath=$(cmd.exe /c 'echo %HOMEDRIVE%%HOMEPATH%' 2>&1 | tr -d '\r') - export wHome=$(wslpath -u "${wHomeWinPath}") - export wDocument="$wHome/Documents" - export wWork="$wDocument/work" -fi +alias kazoo="cd ${wKazoo}" +alias kz="cd ${wKazoo}/kazoo-master; export KAZOO_SRC=${wKazoo}/kazoo-master" +alias kz3="cd ${wKazoo}/kazoo-4.3; export KAZOO_SRC=${wKazoo}/kazoo-4.3" +alias kz5="cd ${wKazoo}/kazoo-5.0; export KAZOO_SRC=${wKazoo}/kazoo-5.0" +# }}} + +# Lang and tools setup {{{ +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 +[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && . "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm +[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && . "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion + +# export PATH=$PATH:$(go env GOPATH)/bin +# }}} + +# Kazoo Stuff {{{ +[ -f ${wKazoo}/kgit-completion.bash ] && . ${wKazoo}/kgit-completion.bash +[ -f ${wKazoo}/kgit ] && alias kgit="${wKazoo}/kgit" -export w2222="$wWork/2600hz" -export wKazoo="$w2222/kazoo" -export KAZOO_SRC="$wKazoo/master" - -alias icedock="cd $wWork/dockerfiles" -alias icework="cd $iceWork" -alias work="cd $wWork" -alias 2222="cd $w2222" -alias kazoo="cd $wKazoo" -alias kz="cd $wKazoo/master; export KAZOO_SRC=$wKazoo/master" -alias kz1="cd $wKazoo/4.1; export KAZOO_SRC=$wKazoo/4.1" -alias kz2="cd $wKazoo/4.2; export KAZOO_SRC=$wKazoo/4.2" -alias kz3="cd $wKazoo/4.3; export KAZOO_SRC=$wKazoo/4.3" +# alias kzdoc="docker compose -f $DOCKER_ROOT/../kazoo-mac-docker/kazoo5-icehess/docker-compose.yml" +alias kzdoc="COMPOSE_FILE=${DOCKER_ROOT}/../kazoo-mac-docker/kazoo5-icehess/docker-compose.yml docker" +complete -F _docker kzdoc +# }}} diff --git a/.bashlocal-opensuse b/.bashlocal-opensuse deleted file mode 100644 index 9674ceb..0000000 --- a/.bashlocal-opensuse +++ /dev/null @@ -1,66 +0,0 @@ -#! /bin/bash - -# Set up ssh-agent -# if [ -z "$(pgrep ssh-agent)" ]; then -# rm -rf /tmp/ssh-* -# eval $(ssh-agent -s) > /dev/null -# else -# export SSH_AGENT_PID=$(pgrep ssh-agent) -# export SSH_AUTH_SOCK=$(find /tmp/ssh-* -name agent.*) -# fi - -# if [ -f ~/.ssh/hesaam_github -a `ssh-add -l | grep -c hesaam_github` -eq 0 ]; then -# ssh-add ~/.ssh/hesaam_github -# fi - -# for gnome-keyring -if [ -n "$DESKTOP_SESSION" ];then - eval $(gnome-keyring-daemon --start 2>/dev/null) - export SSH_AUTH_SOCK -fi - -[ -f ~/.fzf.bash ] && source ~/.fzf.bash - -export iceWork="$HOME/work" -export wWork="$iceWork" - -export w2222="$wWork/2600hz" -export wKazoo="$w2222" -export KAZOO_SRC="$wKazoo/master" - -alias icedock="cd $wWork/dockerfiles" -alias icework="cd $iceWork" -alias work="cd $wWork" -alias 2222="cd $w2222" -alias kazoo="cd $wKazoo" -alias kz="cd $wKazoo/master; export KAZOO_SRC=$wKazoo/master" -alias kz1="cd $wKazoo/4.1; export KAZOO_SRC=$wKazoo/4.1" -alias kz2="cd $wKazoo/4.2; export KAZOO_SRC=$wKazoo/4.2" -alias kz3="cd $wKazoo/4.3; export KAZOO_SRC=$wKazoo/4.3" - -# for python-pip user -export PATH="$PATH:$HOME/.local/bin" - -[ -f ${wKazoo}/master/kgit-completion.bash ] && . ${wKazoo}/master/kgit-completion.bash - -# User specific aliases and functions - -#export IP_ADDR="$(ip addr show eth0 | egrep -o 'inet [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sed 's/inet //g')" -#export _HOSTNAME="kazoo5.2600hz.com" - -[ -d "$HOME/.nvm" ] && export NVM_DIR="$HOME/.nvm" -[ -s "/usr/share/nvm/nvm.sh" ] && . "/usr/share/nvm/nvm.sh" # This loads nvm -[ -s "/usr/share/nvm/bash_completion" ] && . "/usr/share/nvm/bash_completion" # This loads nvm bash_completion - -[ -r /usr/bin/ag ] && alias kag="ag -U --hidden" - -export FETCH_AS="git@github.com:" -export ADMIN_HASH="d2abaa37a7c3db1137d385e1d8c15fd2" -export ADMIN_ID="156e05e8a12fd138540cd2017a97e371" -export ADMIN_BASIC="$ADMIN_ID:$ADMIN_HASH" - -export COMMIO_APPS="commio-accounts commio-components commio-login commio-navbar commio-toolbar commio-userportal kazoo-js-sdk" -export COMMIO_EVERYTHING="commio-core $COMMIO_APPS" - -export COMMIO_APPS2="commio-cluster-manager $COMMIO_APPS" -export COMMIO_EVERYTHING2="commio-cluster-manager $COMMIO_EVERYTHING" diff --git a/.bashrc b/.bashrc index 338d1b9..edd0cac 100644 --- a/.bashrc +++ b/.bashrc @@ -1,17 +1,58 @@ +# Init Path {{{ +[ -d /usr/local/sbin ] && export PATH="/usr/local/sbin:${PATH}" +[ -d /usr/local/bin ] && export PATH="/usr/local/bin:${PATH}" + +[ -d /usr/local/opt/coreutils/libexec/gnubin ] && export PATH="/usr/local/opt/coreutils/libexec/gnubin:${PATH}" +[ -d /usr/local/opt/findutils/libexec/gnubin ] && export PATH="/usr/local/opt/findutils/libexec/gnubin:${PATH}" +[ -d /usr/local/opt/gnu-sed/libexec/gnubin ] && export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:${PATH}" + +[ -d /opt/homebrew/opt/coreutils/libexec/gnubin ] && export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:${PATH}" +[ -d /opt/homebrew/opt/findutils/libexec/gnubin ] && export PATH="/opt/homebrew/opt/findutils/libexec/gnubin:${PATH}" +[ -d /opt/homebrew/opt/gnu-sed/libexec/gnubin ] && export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:${PATH}" + +[ -d /opt/ruby/bin ] && export PATH="/usr/local/opt/ruby/bin:${PATH}" +[ -d /opt/homebrew/opt/ruby/bin ] && export PATH="/opt/homebrew/opt/ruby/bin:${PATH}" + +[ -d "$HOME/bin" ] && export PATH="$HOME/bin:${PATH}" + +if [ -f /opt/homebrew/bin/brew ]; then + # this is slow, that is why we export directly + # eval "$(/opt/homebrew/bin/brew shellenv)" + export HOMEBREW_PREFIX="/usr/local"; + export HOMEBREW_CELLAR="/usr/local/Cellar"; + export HOMEBREW_REPOSITORY="/usr/local/Homebrew"; + export PATH="/usr/local/bin:/usr/local/sbin${PATH+:$PATH}"; + export MANPATH="/usr/local/share/man${MANPATH+:$MANPATH}:"; + export INFOPATH="/usr/local/share/info:${INFOPATH:-}"; +elif [ -f /usr/local/bin/brew ]; then + # this is slow, that is why we export directly + # eval "$(/usr/local/bin/brew shellenv)" + export HOMEBREW_PREFIX="/opt/homebrew"; + export HOMEBREW_CELLAR="/opt/homebrew/Cellar"; + export HOMEBREW_REPOSITORY="/opt/homebrew"; + export PATH="/opt/homebrew/bin:/opt/homebrew/sbin${PATH+:$PATH}"; + export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:"; + export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}"; +fi +# }}} + # If not running interactively, don't do anything if [[ $- != *i* ]] ; then - [ -d /usr/local/sbin ] && export PATH="/usr/local/sbin:$PATH" - [ -d /usr/local/bin ] && export PATH="/usr/local/bin:$PATH" - [ -f /opt/homebrew/bin/brew ] && eval "$(/opt/homebrew/bin/brew shellenv)" return fi -[ -f /opt/homebrew/bin/brew ] && eval "$(/opt/homebrew/bin/brew shellenv)" + +# Good Shell {{{ +# If set, bash checks the window size after each external (non-builtin) command and, if necessary, updates the values of LINES +# and COLUMNS. This option is enabled by default. shopt -s checkwinsize +# shut up macOS cwd echo (in Terminal app, iTerm is okay): +# > It updates the prompt to echo the Current Working Directory (CWD) and is defined in /etc/bashrc update_terminal_cwdprintf() { echo -n } +export BASH_SILENCE_DEPRECATION_WARNING=1 # append new history items to .bash_history shopt -s histappend @@ -42,17 +83,22 @@ if type -P dircolors >/dev/null ; then eval $(dircolors -b /etc/DIR_COLORS) fi fi +# }}} +# Shell Prompt {{{ if [ -f /usr/share/git/git-prompt.sh ]; then source /usr/share/git/git-prompt.sh -elif [ -f ~/.git-prompt.sh ]; then - source ~/.git-prompt.sh +elif [ -f "~/.git-prompt.sh" ]; then + source "~/.git-prompt.sh" elif [ -f /usr/share/git-core/contrib/completion/git-prompt.sh ]; then # CentOS source /usr/share/git-core/contrib/completion/git-prompt.sh -# elif [ -f "/opt/homebrew/opt/bash-git-prompt/share/gitprompt.sh" ]; then -# __GIT_PROMPT_DIR="/opt/homebrew/opt/bash-git-prompt/share" -# source "/opt/homebrew/opt/bash-git-prompt/share/gitprompt.sh" +elif [ -f /usr/local/opt/bash-git-prompt/share/gitprompt.sh ]; then + __GIT_PROMPT_DIR=/usr/local/opt/bash-git-prompt/share + source /usr/local/opt/bash-git-prompt/share/gitprompt.sh +elif [ -f /opt/homebrew/opt/bash-git-prompt/share/gitprompt.sh ]; then + __GIT_PROMPT_DIR=/opt/homebrew/opt/bash-git-prompt/share + source /opt/homebrew/opt/bash-git-prompt/share/gitprompt.sh else __git_ps1() { return $? @@ -75,137 +121,117 @@ else #PS1="\[\e[01;31m\]┌─[\[\e[01;35m\u\e[01;31m\]]──[\[\e[00;37m\]${HOSTNAME%%.*}\[\e[01;32m\]]:\w$\[\e[01;31m\]\n\[\e[01;31m\]└──\[\e[01;36m\]>>\[\e[0m\]" fi -#Use color for ls and grep -# [[ "$OSTYPE" =~ linux* ]] && alias ls='ls -G' || alias ls='ls --color=auto' -alias ls='ls --color=auto' -[[ "$OSTYPE" == "darwin"* || "$OSTYPE" == "freebsd"* ]] && alias grep='grep --colour=auto' || grep='grep --color=auto' -type colordiff > /dev/null 2>&1 && alias diff='colordiff' # requires colordiff package -alias less='less -R' - PS2='> ' PS3='> ' PS4='+ ' +# }}} -# Common junk -[[ -s "$HOME/.dotfiles-site/bash_alias" ]] && source "$HOME/.dotfiles-site/bash_alias" -#[[ -s "$HOME/.dotfiles-site/functions" ]] && source "$HOME/.dotfiles-site/functions" +# Setting bash_completion {{{ +## Common (Ubuntu? Debian?) +[ -r /etc/bash_completion ] && . /etc/bash_completion +## Arch (it is already being source by /etc/bash.bashrc) +# [ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion -## setting bash_completion -[ -r /etc/bash_completion ] && . /etc/bash_completion -[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion +# macOS +[ -r /usr/local/etc/profile.d/bash_completion.sh ] && . /usr/local/etc/profile.d/bash_completion.sh +[ -r /opt/homebrew/etc/profile.d/bash_completion.sh ] && . /opt/homebrew/etc/profile.d/bash_completion.sh +# }}} -[ -r /usr/share/bash_completion/bash_completion ] && . /usr/share/bash_completion/bash_completion -[[ -r "/opt/homebrew/etc/profile.d/bash_completion.sh" ]] && . "/opt/homebrew/etc/profile.d/bash_completion.sh" +# Aliases {{{ +alias ..='cd ..' +alias ...='cd ../..' -[ -d "/usr/local/opt/coreutils/libexec/gnubin" ] && export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" -[ -d /usr/local/opt/findutils/libexec/gnubin ] && export PATH="/usr/local/opt/findutils/libexec/gnubin:$PATH" -[ -d "/opt/homebrew/opt/coreutils/libexec/gnubin" ] && export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" -[ -d /opt/homebrew/opt/findutils/libexec/gnubin ] && export PATH="/opt/homebrew/opt/findutils/libexec/gnubin:$PATH" -[ -d /opt/homebrew/opt/gnu-sed/libexec/gnubin ] && export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH" -[ -d "$HOME/bin" ] && export PATH="$HOME/bin:$PATH" -[ -d "$HOME/.local/bin" ] && export PATH="$HOME/.local/bin:$PATH" +alias ll='ls -lAF' +alias simplehttpd='python3 -m http.server'; +alias simplehttpd2='python -m SimpleHTTPServer'; +alias jsonformat='python -m json.tool' if type -P nvim >/dev/null ; then - alias vim="nvim" - export EDITOR="nvim" -else - export EDITOR="vim" + alias vim='nvim' + export EDITOR='nvim' +elif type -P vim >/dev/null ; then + export EDITOR='vim' +elif type -P vi >/dev/null ; then + alias vim='vi' + export EDITOR='vi' +fi +alias emacs='emacs --no-window-system' + +# [[ "$OSTYPE" == "darwin"* || "$OSTYPE" == "freebsd"* ]] && alias grep='grep --colour=auto' || grep='grep --color=auto' +if [ -n "${OSTYPE}" ]; then + if [ "${OSTYPE}" == 'linux-gnu' ]; then + alias grep='grep --color=auto' + else + alias grep='grep --colour=auto' + fi fi -#[ -r /usr/bin/mate-terminal ] && export TERMINAL="mate-terminal" -[ -r /usr/bin/termite ] && export TERMINAL="termite" -[ -r /usr/bin/ksshaskpass ] && export SSH_ASKPASS="/usr/bin/ksshaskpass" -[ -r $XDG_RUNTIME_DIR/ssh-agent.socket ] && export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket" +# [[ "$OSTYPE" =~ linux* ]] && alias ls='ls -G' || alias ls='ls --color=auto' +alias ls='ls --color=auto' + +type colordiff > /dev/null 2>&1 && alias diff='colordiff' -export PAGER="less" +type less >/dev/null 2>&1 && alias less='less -R' +type less >/dev/null 2>&1 && export PAGER='less' -PLATFORM=`uname -s` -if [ x"`uname -a | grep -o Microsoft | uniq`" = x"Microsoft" ]; then - PLATFORM="Microsoft" -elif [ x"`uname -a | grep -o Darwin | uniq`" = x"Darwin" ]; then - PLATFORM="Darwin" +alias config="git --git-dir=${HOME}/.dotfiles/ --work-tree=${HOME}" +if [ -f /usr/share/bash-completion/completions/git ]; then + source /usr/share/bash-completion/completions/git + __git_complete config __git_main fi -alias config='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME' +# }}} -if [ -e ~/.bashlocal ]; then - . ~/.bashlocal -fi +[ -s "${HOME}/.dotfiles-site/functions" ] && source "${HOME}/.dotfiles-site/functions" -_info () { - printf "\e[1;36m::\e[1;37m $* \e[00m \n" >&2; -} +# PLATFORM=`uname -s` +# if [ x"`uname -a | grep -o Microsoft | uniq`" = x"Microsoft" ]; then +# PLATFORM="Microsoft" +# elif [ x"`uname -a | grep -o Darwin | uniq`" = x"Darwin" ]; then +# PLATFORM="Darwin" +# fi -_error () { - printf "\e[1;37m::\e[1;31m $* \e[00m \n" >&2; -} +# fzf {{{ +[ -f /usr/share/fzf/key-bindings.bash ] && . /usr/share/fzf/key-bindings.bash +[ -f /usr/share/fzf/completion.bash ] && . /usr/share/fzf/completion.bash +[ -f /usr/local/opt/fzf/shell/completion.bash ] && . /usr/local/opt/fzf/shell/completion.bash +[ -f /opt/homebrew/opt/fzf/shell/completion.bash ] && . /opt/homebrew/opt/fzf/shell/completion.bash +# }}} -_die () { - _error "$1" - exit 1 -} +# Work Dirs {{{ +export wWork="${HOME}/work" +export iceDockerRoot="${wWork}/dockerfiles/kazoo/composer/docker" -# use it like `loop_do "$SOME_DIRS" 'do your thing;'`. -# don't be evil though, eval is dangerous. -# I like `fn` from https://github.com/spencertipping/bash-lambda -# -# Also there are some other variation: -# (1) if no lazy evaluation, no need for eval -# function x() { echo "Hello world"; } -# function around() { echo before; $1; echo after; } -# around x -# -# (2) same as above with args for x -# function x() { echo "x(): Passed $1 and $2"; } -# function around() { echo before; "$@"; echo after; } -# around x 1st 2nd -# -# (3) using sub-shell; "x" must be a command or function -# function x() { pushd $1 ; git branch -vv | grep ": gone]" | grep -v "\*" | awk '{ print $1; }' | xargs git branch -D ; popd; } -# for dir in $COMMIO ; do ("x" $dir) ; done -# -# -# Usage: -# loop_do "applications/*/" "do_in_dir \$loop_i 'git status --branch -s'" -# loop_do "applications/*/" "do_in_dir \$loop_i 'rm-if-gone'" -# loop_do "$COMMIO_APPS" "do_in_dir \$loop_i 'git commit -a -m \"setting base_branch to 1.0\"'" -# loop_do "$COMMIO_APPS" "do_in_dir \$loop_i 'nvim .circleci/config.yml'" -function loop_do() { - local loop_i= stop= ret= - case $1 in - -stop) - stop=1 - shift - ;; - *) - ;; - esac - for loop_i in $1 ; do - _info "doing $loop_i" - eval $2 - ret=$? - [ -n "$stop" ] && [ $ret -ne 0 ] && _error "command failed" && return - done - - return $ret -} +alias icedock="cd ${wWork}/dockerfiles" +alias work="cd $wWork" +# }}} -function do_in_dir() { - local ret= - if [ ! -d "$1" ]; then - echo "$1 does not exists" - return 1 - fi - pushd "$1" > /dev/null - eval "$2" - ret=$? - popd > /dev/null - return $ret -} +# WSL Dirs {{{ +if [ -d /mnt/c/hesaam ]; then + export wslHome="/mnt/c/Users/hesaam" + export wslDocument="${wHome}/Documents" + export wslWork="${wDocument}/work" + alias wslHome="cd ${wslHome}" + alias wslWork="cd ${wslWork}" +fi +# }}} + +# Progamming Lang Settings {{{ +export ERL_AFLAGS="-kernel shell_history enabled ${ERL_AFLAGS}" +# }}} + +if [ -e ~/.bashlocal ]; then + . ~/.bashlocal +fi + + +## Here goes garbage forking stupid apps shitting their shits here: +# # BEGIN_KITTY_SHELL_INTEGRATION -if test -n "$KITTY_INSTALLATION_DIR" -a -e "$KITTY_INSTALLATION_DIR/shell-integration/bash/kitty.bash"; then source "$KITTY_INSTALLATION_DIR/shell-integration/bash/kitty.bash"; fi +if test -n "$KITTY_INSTALLATION_DIR" -a -e "${KITTY_INSTALLATION_DIR}/shell-integration/bash/kitty.bash"; then source "$KITTY_INSTALLATION_DIR/shell-integration/bash/kitty.bash"; fi # END_KITTY_SHELL_INTEGRATION [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/asdf-direnv/bashrc" ] && source "${XDG_CONFIG_HOME:-$HOME/.config}/asdf-direnv/bashrc" +. "${HOME}/.cargo/env" diff --git a/.dotfiles-site/bash_alias b/.dotfiles-site/bash_alias deleted file mode 100644 index 6ce0a45..0000000 --- a/.dotfiles-site/bash_alias +++ /dev/null @@ -1,102 +0,0 @@ -# -# MODIFIED COAMMANDS: -# ------------------- -# -#alias diff='colordiff' # it's now set in .bashrc, requires colordiff package -#alias grep='grep --color=auto' # it's now set in .bashrc -#alias more='less' -#alias df='df -h' -#alias du='du -c -h' - -#alias mkdir='mkdir -p -v' -#alias nano='nano -w' -#alias ping='ping -c 5' - -alias ..='cd ..' -alias ...='cd ../..' - -alias cdimenpar='cd ~/Developing/Projects/ImenPardis/' -alias cdpspar='cd ~/Developing/Projects/ImenPardis/PSPardis/' - -# -# NEW COMMANDS: -# ------------- -# -#alias da='date "+%A, %B %d, %Y [%T]"' -#alias du1='du --max-depth=1' -alias hist='history | grep' # requires an argument -alias whatismyip="curl -s http://checkip.dyndns.com/ | sed 's/[^0-9\.]//g'" # or: -#alias whatismyip='dig +short myip.opendns.com @resolver1.opendns.com' -alias psgrep='ps aux | grep $1' -# alias `simplehttpd` to start a simple webserver in the current director -alias simplehttpd='python -m SimpleHTTPServer 8888 >/dev/null 2>&1&'; - -if [ $UID -ne 0 ]; then - alias httpdump="sudo tcpdump -i eth0 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\"" - alias openports='sudo netstat --all --numeric --programs --inet --inet6' - alias localip="sudo ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'" -else - alias httpdump="tcpdump -i eth0 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\"" - alias openports='netstat --all --numeric --programs --inet --inet6' - alias localip="ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'" -fi - - -# -# PRIVILEGED ACCESS: -# ------------------ -# -#if [ $UID -ne 0 ]; then -# alias sudo='sudo ' -# alias scat='sudo cat' -# alias svim='sudo vim' -# alias snano='sudo nano' - #alias root='sudo su' -# alias reboot='sudo reboot' -# alias halt='sudo halt' - #alias update='sudo pacman -Su' - #alias netcfg='sudo netcfg2' -#fi - -# -# LS: -# --- -# -#alias ls='ls --color=auto' # it's now set in .bashrc -#alias lr='ls -R' # recursive ls -alias lf='ls -F' -alias ll='ls -lAF' -alias la='ls -A' -alias lx='ll -BX' # sort by extension -alias lz='ll -rS' # sort by size -alias lt='ll -rt' # sort by date -alias lm='la | more' - -# -# SAFETY FEATURES: -# ---------------- -# -#alias cp='cp -i' -#alias mv='mv -i' -#alias rm='rm -I' # 'rm -i' prompts for every file -#alias ln='ln -i' -#alias chown='chown --preserve-root' -#alias chmod='chmod --preserve-root' -#alias chgrp='chgrp --preserve-root' - -# -# PACMAN ALIASES (if applicable, replace 'pacman' with 'yaourt'/'pacaur'/whatever): -# --------------------------------------------------------------------------------- -# -#alias pac="pacman -S" # default action - install one or more packages -#alias pacu="pacman -Syu" # '[u]pdate' - upgrade all packages to their newest version -#alias pacs="pacman -Ss" # '[s]earch' - search for a package using one or more keywords -#alias paci="pacman -Si" # '[i]nfo' - show information about a package -#alias pacr="pacman -R" # '[r]emove' - uninstall one or more packages -#alias pacl="pacman -Sl" # '[l]ist' - list all packages of a repository -#alias pacll="pacman -Qqm" # '[l]ist [l]ocal' - list all packages which were locally installed (e.g. AUR packages) -#alias paclo="pacman -Qdt" # '[l]ist [o]rphans' - list all packages which are orphaned -#alias paco="pacman -Qo" # '[o]wner' - determine which package owns a given file -#alias pacf="pacman -Ql" # '[f]iles' - list all files installed by a given package -#alias pacc="pacman -Sc" # '[c]lean cache' - delete all not currently installed package files -#alias pacm="makepkg -fci" # '[m]ake' - make package from PKGBUILD file in current directory diff --git a/.dotfiles-site/functions b/.dotfiles-site/functions index 0104b6b..dc87cd8 100644 --- a/.dotfiles-site/functions +++ b/.dotfiles-site/functions @@ -1,155 +1,110 @@ -# Test if HTTP compression (RFC 2616 + SDCH) is enabled for a given URL. -# Send a fake UA string for sites that sniff it instead of using the Accept-Encoding header. (Looking at you, ajax.googleapis.com!) -httpcompression() { - encoding="$(curl -LIs -H 'User-Agent: Mozilla/5 Gecko' -H 'Accept-Encoding: gzip,deflate,compress,sdch' "$1" | grep '^Content-Encoding:')" && echo "$1 is encoded using ${encoding#* }" || echo "$1 is not using any encoding" -} - -# All the dig info -digga() { - dig +nocmd "$1" any +multiline +noall +answer -} - -# Show a one-line process tree of the given process, defaulting to the current shell. -process-tree () { - pid="${1:-$$}"; - orig_pid="$pid"; - local commands=(); - while [ "$pid" != "$ppid" ]; do - # Read the parent's process ID and the current process's command line. - { read -d ' ' ppid; read command; } < <(ps c -p "$pid" -o ppid= -o command= | sed 's/^ *//'); - - # Stop when we have reached the first process, or an sshd/login process. - [ "$ppid" -eq 0 -o "$ppid" -eq 1 -o "$command" = 'login' -o "$command" = 'sshd' ] && break; - - # Insert the command in the front of the process array. - commands=("$command" "${commands[@]}"); - - # Prepare for the next iteration. - pid="$ppid"; - ppid=; - done; - - # Hide the first bash process. - set -- "${commands[@]}"; - if [ "$1" = '-bash' -o "$1" = 'bash' ]; then - shift; - commands=("$@"); - fi; - - # Print the tree with the specified separator. - separator='→'; - output="$(IFS="$separator"; echo "${commands[*]}")"; - echo "${output//$separator/ $separator }"; -} - # Convert the parameters or STDIN to lowercase. lc () { - if [ $# -eq 0 ]; then - tr '[:upper:]' '[:lower:]'; - else - tr '[:upper:]' '[:lower:]' <<< "$@"; - fi; + if [ $# -eq 0 ]; then + tr '[:upper:]' '[:lower:]'; + else + tr '[:upper:]' '[:lower:]' <<< "$@"; + fi; } # Convert the parameters or STDIN to uppercase. uc () { - if [ $# -eq 0 ]; then - tr '[:lower:]' '[:upper:]'; - else - tr '[:lower:]' '[:upper:]' <<< "$@"; - fi; + if [ $# -eq 0 ]; then + tr '[:lower:]' '[:upper:]'; + else + tr '[:lower:]' '[:upper:]' <<< "$@"; + fi; } -# Open the man page for the previous command. -lman () { set -- $(fc -nl -1); while [ "$#" -gt 0 -a '(' "sudo" = "$1" -o "-" = "${1:0:1}" ')' ]; do shift; done; man "$1" || help "$1"; } +# Print the given text in the center of the screen. +function center { + width=$(tput cols); + str="$@"; + len=${#str}; + [ $len -ge $width ] && echo "$str" && return; + for ((i = 0; i < $(((($width - $len)) / 2)); i++)); do + echo -n " "; + done; + echo "$str"; +} function line { - width=$(tput cols); - str=${1--}; - len=${#str}; - for ((i = 0; i < $width; i += $len)); do - echo -n "${str:0:$(($width - $i))}"; - done; - echo; + width=$(tput cols); + str=${1--}; + len=${#str}; + for ((i = 0; i < $width; i += $len)); do + echo -n "${str:0:$(($width - $i))}"; + done; + echo; } -# Print the given text in the center of the screen. -function center { - width=$(tput cols); - str="$@"; - len=${#str}; - [ $len -ge $width ] && echo "$str" && return; - for ((i = 0; i < $(((($width - $len)) / 2)); i++)); do - echo -n " "; - done; - echo "$str"; +_info () { + printf "\e[1;36m::\e[1;37m $* \e[00m \n" >&2; } -# Try to make sense of the date. It supports everything GNU date knows how to -# parse, as well as UNIX timestamps. It formats the given date using the -# default GNU date format, which you can override using "--format='%x %y %z'. -# -# Examples of input and output: -# -# $ whenis 1234567890 # UNIX timestamps -# Sat Feb 14 00:31:30 CET 2009 -# -# $ whenis +1 year -3 months # relative dates -# Fri Jul 20 21:51:27 CEST 2012 +_error () { + printf "\e[1;37m::\e[1;31m $* \e[00m \n" >&2; +} + +_die () { + _error "$1" + exit 1 +} + +# use it like `loop_do "$SOME_DIRS" 'do your thing;'`. +# don't be evil though, eval is dangerous. +# I like `fn` from https://github.com/spencertipping/bash-lambda # -# $ whenis 2011-10-09 08:07:06 # MySQL DATETIME strings -# Sun Oct 9 08:07:06 CEST 2011 +# Also there are some other variation: +# (1) if no lazy evaluation, no need for eval +# function x() { echo "Hello world"; } +# function around() { echo before; $1; echo after; } +# around x # -# $ whenis 1979-10-14T12:00:00.001-04:00 # HTML5 global date and time -# Sun Oct 14 17:00:00 CET 1979 +# (2) same as above with args for x +# function x() { echo "x(): Passed $1 and $2"; } +# function around() { echo before; "$@"; echo after; } +# around x 1st 2nd # -# $ (TZ=America/Vancouver whenis) # Current time in Vancouver -# Thu Oct 20 13:04:20 PDT 2011 +# (3) using sub-shell; "x" must be a command or function +# function x() { pushd $1 ; git branch -vv | grep ": gone]" | grep -v "\*" | awk '{ print $1; }' | xargs git branch -D ; popd; } +# for dir in $COMMIO ; do ("x" $dir) ; done # -# When requesting a different timezone like in the last example, make sure to -# execute the command in a subshell to avoid changing your timezone for the -# rest of the session. # -# For more info, check out http://kak.be/gnudateformats. -function whenis { - local error='Unable to parse that using http://kak.be/gnudateformats'; - - # Default GNU date format as seen in date.c from GNU coreutils. - local format='%a %b %e %H:%M:%S %Z %Y'; - if [[ "$1" =~ ^--format= ]]; then - format="${1#--format=}"; - shift; - fi; - - # Concatenate all arguments as one string specifying the date. - local date="$*"; - [[ "$date" =~ ^[[:space:]]*$ ]] && date='now'; - - if [[ "$OSTYPE" =~ ^darwin ]]; then - # Use PHP on OS X, where "date" is not GNU's. - php -r ' - error_reporting(-1); - $format = $_SERVER["argv"][1]; - $date = $_SERVER["argv"][2]; - if (!is_numeric($date)) { - $date = strtotime($date); - if ($date === false) { - fputs(STDERR, $_SERVER["argv"][3] . PHP_EOL); - exit(1); - } - } - echo strftime($format, $date), PHP_EOL; - ' -- "$format" "$date" "$error"; - else - # Use GNU date in all other situations. - [[ "$date" =~ ^[0-9]+$ ]] && date="@$date"; - date -d "$date" +"$format"; - fi; +# Usage: +# loop_do "applications/*/" "do_in_dir \$loop_i 'git status --branch -s'" +# loop_do "applications/*/" "do_in_dir \$loop_i 'rm-if-gone'" +# loop_do "$COMMIO_APPS" "do_in_dir \$loop_i 'git commit -a -m \"setting base_branch to 1.0\"'" +# loop_do "$COMMIO_APPS" "do_in_dir \$loop_i 'nvim .circleci/config.yml'" +function loop_do() { + local loop_i= stop= ret= + case $1 in + -stop) + stop=1 + shift + ;; + *) + ;; + esac + for loop_i in $1 ; do + _info "doing $loop_i" + eval $2 + ret=$? + [ -n "$stop" ] && [ $ret -ne 0 ] && _error "command failed" && return + done + + return $ret } - -genpasswd() { - local l=$1 - [ "$l" == "" ] && l=16 - tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs +function do_in_dir() { + local ret= + if [ ! -d "$1" ]; then + echo "$1 does not exists" + return 1 + fi + pushd "$1" > /dev/null + eval "$2" + ret=$? + popd > /dev/null + return $ret } diff --git a/.emacs.d/init.el b/.emacs.d/init-not-working.el similarity index 100% rename from .emacs.d/init.el rename to .emacs.d/init-not-working.el diff --git a/.gitignore b/.gitignore index 093f1d0..21e4dd9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ .~lock.* elrang_ls.config *erlang_ls.config* +./.bashlocal +./.ssh