# --- environment variables ----------------------------------------------------------------------- export VISUAL=vim export EDITOR="$VISUAL" export LEDGER_FILE="~/ledger/main.ledger" # --- aliases ------------------------------------------------------------------------------------- alias ledger='ledger --date-format "%Y-%m-%d" --price-db ~/ledger/prices.db' alias ledger-cash='ledger register cash --tail 15' alias ledger-checking='ledger register checking --tail 15' alias ledger-worth='ledger bal ^assets ^liabilities' alias enscript='enscript -Bc' # --- prompt command ------------------------------------------------------------------------------ _bash_prompt_config() { local USER_SYMBOL="\u" local HOST_SYMBOL="\h" local ESC_OPEN="\[" local ESC_CLOSE="\]" if tput setaf >/dev/null 2>&1 ; then _setaf () { tput setaf "$1" ; } local RESET="${ESC_OPEN}$( { tput sgr0 || tput me ; } 2>/dev/null )${ESC_CLOSE}" local BOLD="$( { tput bold || tput md ; } 2>/dev/null )" else # Fallback _setaf () { echo "\033[0;$(($1+30))m" ; } local RESET="\033[m" local BOLD="" ESC_OPEN="" ESC_CLOSE="" fi # Normal colors local BLACK="${ESC_OPEN}$(_setaf 0)${ESC_CLOSE}" local RED="${ESC_OPEN}$(_setaf 1)${ESC_CLOSE}" local GREEN="${ESC_OPEN}$(_setaf 2)${ESC_CLOSE}" local YELLOW="${ESC_OPEN}$(_setaf 3)${ESC_CLOSE}" local BLUE="${ESC_OPEN}$(_setaf 4)${ESC_CLOSE}" local VIOLET="${ESC_OPEN}$(_setaf 5)${ESC_CLOSE}" local CYAN="${ESC_OPEN}$(_setaf 6)${ESC_CLOSE}" local WHITE="${ESC_OPEN}$(_setaf 7)${ESC_CLOSE}" # Bright colors local BRIGHT_GREEN="${ESC_OPEN}$(_setaf 10)${ESC_CLOSE}" local BRIGHT_YELLOW="${ESC_OPEN}$(_setaf 11)${ESC_CLOSE}" local BRIGHT_BLUE="${ESC_OPEN}$(_setaf 12)${ESC_CLOSE}" local BRIGHT_VIOLET="${ESC_OPEN}$(_setaf 13)${ESC_CLOSE}" local BRIGHT_CYAN="${ESC_OPEN}$(_setaf 14)${ESC_CLOSE}" local BRIGHT_WHITE="${ESC_OPEN}$(_setaf 15)${ESC_CLOSE}" # Bold colors local BLACK_BOLD="${ESC_OPEN}${BOLD}$(_setaf 0)${ESC_CLOSE}" local RED_BOLD="${ESC_OPEN}${BOLD}$(_setaf 1)${ESC_CLOSE}" local GREEN_BOLD="${ESC_OPEN}${BOLD}$(_setaf 2)${ESC_CLOSE}" local YELLOW_BOLD="${ESC_OPEN}${BOLD}$(_setaf 3)${ESC_CLOSE}" local BLUE_BOLD="${ESC_OPEN}${BOLD}$(_setaf 4)${ESC_CLOSE}" local VIOLET_BOLD="${ESC_OPEN}${BOLD}$(_setaf 5)${ESC_CLOSE}" local CYAN_BOLD="${ESC_OPEN}${BOLD}$(_setaf 6)${ESC_CLOSE}" local WHITE_BOLD="${ESC_OPEN}${BOLD}$(_setaf 7)${ESC_CLOSE}" # Expose the variables we need in prompt command P_USER=${BRIGHT_GREEN}${USER_SYMBOL} P_HOST=${CYAN}${HOST_SYMBOL} P_WHITE=${WHITE_BOLD} P_BLUE=${BLUE_BOLD} P_GREEN=${YELLOW_BOLD} P_YELLOW=${GREEN_BOLD} P_RED=${RED} P_RESET=${RESET} } _bash_prompt_config unset _bash_prompt_config parse_git_branch() { local OUT=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` if [ "$OUT" != "" ]; then echo "$OUT"; fi } bash_prompt_command() { # conda if [ "$CONDA_DEFAULT_ENV" != "" ]; then P_CONDA="conda@$CONDA_DEFAULT_ENV " else P_CONDA="" fi # git if [ "$(parse_git_branch)" != "" ]; then P_GIT="git@$(parse_git_branch) " else P_GIT="" fi # construct export PS1="${P_YELLOW}\u@\h ${P_GREEN}${P_CONDA}${P_RED}${P_GIT}${P_BLUE}\W ${P_YELLOW}\\$ ${P_RESET}" } PROMPT_COMMAND=bash_prompt_command # --- functions ----------------------------------------------------------------------------------- function countdown(){ secs=$(($1 * 60)); date1=$((`date +%s` + "$secs")); while [ "$date1" -ge `date +%s` ]; do echo -ne "$(date -u --date @$(($date1 - `date +%s`)) +%H:%M:%S)\r"; sleep 0.1 done } function git-commit-with-timestamp(){ print-green $(pwd) git remote update git pull if ! git diff --quiet then echo "COMMITING" git add --all git commit -m "$(date +"%Y-%m-%d %H:%M")" git push fi } function git-sync-all(){ while read -r line do print-line cd "$line" git-commit-with-timestamp done < ~/.git-synced cd ~ } function print-cyan { CYAN='\033[0;36m' NC='\033[0m' # No Color printf "${CYAN}$*${NC}\n" } function print-green { GREEN='\033[0;32m' NC='\033[0m' # No Color printf "${GREEN}$*${NC}\n" } function print-line { print-green "%`tput cols`s"|tr ' ' '#' } function print-yellow { YELLOW='\033[0;33m' NC='\033[0m' # No Color printf "${YELLOW}$*${NC}\n" } function pip3-update-all { pip3 freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U }