From c8d06cc71c4d52f78c754e15388ef3ef7df55f19 Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Tue, 1 Dec 2020 20:15:47 -0800 Subject: [PATCH] Clean up bash config --- bash/aliases | 52 ++++++++++---------------- bash/colors | 75 ------------------------------------- bash/completion | 7 +++- bash/direnv-hook | 11 ------ bash/ensure-ssh-agent | 26 ------------- bash/environment | 32 +--------------- bash/functions | 14 +------ bash/path | 4 +- bash/prompt | 87 ++++++++++++++++++++++++++++++++++++++++--- bashrc | 29 +++++++++++++-- 10 files changed, 136 insertions(+), 201 deletions(-) delete mode 100644 bash/colors delete mode 100644 bash/direnv-hook delete mode 100755 bash/ensure-ssh-agent diff --git a/bash/aliases b/bash/aliases index 8a648f0..29dad0e 100644 --- a/bash/aliases +++ b/bash/aliases @@ -1,4 +1,22 @@ -#!/usr/bin/env bash +alias ll='ls -alF' +alias curl='curl --proto-default https --silent ' + +alias 644='chmod 644' +alias 755='chmod 755' +alias 600='chmod 600' +alias 700='chmod 700' +alias +x='chmod +x' + +alias rsync-win='rsync --recursive --verbose --times --modify-window=1 ' +alias simple-http-server='python3 -m http.server' +# shellcheck disable=SC1004 +alias wget-opendir='wget --recursive --level 0 --continue --no-clobber \ + --no-parent --execute robots=off --random-wait --limit-rate=800k \ + --reject=html,htm,index' + +alias numfiles='find . -maxdepth 1 -type f | wc -l' +alias slugify="sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z" +alias take='sudo chown $(whoami):$(whoami) ' if [[ $(uname) == Darwin ]]; then alias ls='ls -G' @@ -13,37 +31,5 @@ fi if command -v bat &> /dev/null ; then alias bat='bat --plain --theme zenburn' - alias cat='bat --plain --theme zenburn --pager never' -fi - -# Move around to common locations -alias desktop="cd ${XDG_DESKTOP_DIR}" -alias podcasts="cd ${XDG_PODCAST_DIR}" -alias code='cd ~/code/ ' -alias music="cd ${XDG_MUSIC_DIR}" -alias documents="cd ${XDG_DOCUMENTS_DIR}" - -if command -v bat &> /dev/null ; then alias cat='bat --style=plain --pager=never' fi - -# Some common aliases -alias ll='ls -alF' -alias df='df -h' -alias du='du -h' -alias curl='curl --proto-default https --silent ' - -alias 644='chmod 644 ' -alias 755='chmod 755 ' -alias 600='chmod 600 ' -alias 700='chmod 500 ' -alias +x='chmod +x ' -alias ..='cd .. ' - -alias rsync-win='rsync --recursive --verbose --times --modify-window=1 ' -alias simple-http-server='python3 -m http.server' -alias wget-opendir='wget -r -l 0 -c -nc -np -e robots=off --random-wait --limit-rate=800000k --reject=html,htm,index' - -alias numfiles='find . -maxdepth 1 -type f | wc -l' -alias slugify="sed -e 's/[^[:alnum:]]/-/g' | tr -s '-' | tr A-Z a-z" -alias take='sudo chown $(whoami):$(whoami) ' diff --git a/bash/colors b/bash/colors deleted file mode 100644 index 5cd4e6a..0000000 --- a/bash/colors +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env bash - -# Reset -color_off='\e[0m' # Text Reset - -# Regular Colors -black='\e[0;30m' # Black -red='\e[0;31m' # Red -green='\e[0;32m' # Green -yellow='\e[0;33m' # Yellow -blue='\e[0;34m' # Blue -purple='\e[0;35m' # Purple -cyan='\e[0;36m' # Cyan -white='\e[0;37m' # White - -# Bold -bblack='\e[1;30m' # Black -bred='\e[1;31m' # Red -bgreen='\e[1;32m' # Green -byellow='\e[1;33m' # Yellow -bblue='\e[1;34m' # Blue -bpurple='\e[1;35m' # Purple -bcyan='\e[1;36m' # Cyan -bwhite='\e[1;37m' # White - -# Underline -ublack='\e[4;30m' # Black -ured='\e[4;31m' # Red -ugreen='\e[4;32m' # Green -uyellow='\e[4;33m' # Yellow -ublue='\e[4;34m' # Blue -upurple='\e[4;35m' # Purple -ucyan='\e[4;36m' # Cyan -uwhite='\e[4;37m' # White - -# Background -on_black='\e[40m' # Black -on_red='\e[41m' # Red -on_green='\e[42m' # Green -on_yellow='\e[43m' # Yellow -on_blue='\e[44m' # Blue -on_purple='\e[45m' # Purple -on_cyan='\e[46m' # Cyan -on_white='\e[47m' # White - -# High Intensty -iblack='\e[0;90m' # Black -ired='\e[0;91m' # Red -igreen='\e[0;92m' # Green -iyellow='\e[0;93m' # Yellow -iblue='\e[0;94m' # Blue -ipurple='\e[0;95m' # Purple -icyan='\e[0;96m' # Cyan -iwhite='\e[0;97m' # White - -# Bold High Intensty -biblack='\e[1;90m' # Black -biRed='\e[1;91m' # Red -biGreen='\e[1;92m' # Green -biYellow='\e[1;93m' # Yellow -biBlue='\e[1;94m' # Blue -biPurple='\e[1;95m' # Purple -biCyan='\e[1;96m' # Cyan -biWhite='\e[1;97m' # White - -# High Intensty backgrounds -on_iblack='\e[0;100m' # Black -on_ired='\e[0;101m' # Red -on_igreen='\e[0;102m' # Green -on_iyellow='\e[0;103m' # Yellow -on_iblue='\e[0;104m' # Blue -on_ipurple='\e[10;95m' # Purple -on_icyan='\e[0;106m' # Cyan -on_iwhite='\e[0;107m' # White - diff --git a/bash/completion b/bash/completion index 0b92919..87b34a8 100644 --- a/bash/completion +++ b/bash/completion @@ -3,16 +3,19 @@ COMPLETION_DIR=/usr/local/etc/bash_completion.d/ if [ -d "$COMPLETION_DIR" ]; then + # shellcheck disable=SC2045 for i in $(ls "$COMPLETION_DIR"); do file="$COMPLETION_DIR/$i" - if [ -r $file ]; then - source $file + if [ -r "${file}" ]; then + # shellcheck disable=SC1090 + source "${file}" fi unset file done unset i fi +# shellcheck disable=SC1091 [[ -f /usr/local/etc/bash_completion ]] && source /usr/local/etc/bash_completion unset COMPLETION_DIR diff --git a/bash/direnv-hook b/bash/direnv-hook deleted file mode 100644 index 5960ace..0000000 --- a/bash/direnv-hook +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -_direnv_hook() { - eval "$(direnv export bash)"; -}; - -if [[ -x $(command -v direnv) ]]; then - if ! [[ "$PROMPT_COMMAND" =~ _direnv_hook ]]; then - PROMPT_COMMAND="_direnv_hook;$PROMPT_COMMAND"; - fi -fi diff --git a/bash/ensure-ssh-agent b/bash/ensure-ssh-agent deleted file mode 100755 index ac2f54f..0000000 --- a/bash/ensure-ssh-agent +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -function tmp-if-needed { - tmpdir=/tmp/ssh-env-$(whoami) - [[ -d $tmpdir ]] || mkdir $tmpdir - chmod 700 "$tmpdir" - chown $(whoami) "$tmpdir" - echo $tmpdir -} - -ENVFILE="${XDG_RUNTIME_DIR:-$(tmp-if-needed)}/ssh-agent.env" - -if [ -f $ENVFILE ] ; then - . $ENVFILE > /dev/null - if ! kill -0 $SSH_AGENT_PID > /dev/null 2>&1; then - eval $(ssh-agent | tee $ENVFILE) - chmod 600 "$ENVFILE" - chown $(whoami) "$ENVFILE" - ssh-add - fi -else - eval $(ssh-agent | tee $ENVFILE) - chmod 600 "$ENVFILE" - chown $(whoami) "$ENVFILE" - ssh-add -fi diff --git a/bash/environment b/bash/environment index 63d2473..6a50083 100644 --- a/bash/environment +++ b/bash/environment @@ -1,41 +1,11 @@ #!/usr/bin/env bash -# append to the history file, don't overwrite it -shopt -s histappend - -# check the window size after each command and, if necessary, -# update the values of LINES and COLUMNS. -shopt -s checkwinsize - -# Disable capslock -if [[ -x $(which setxkbmap) ]]; then - if [[ $(uname) == Linux ]]; then - setxkbmap -option ctrl:nocaps - fi -fi - export EDITOR=vim export BROWSER=firefox -#export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" -# don't put duplicate lines in the history. See bash(1) for more options -# ... or force ignoredups and ignorespace export HISTCONTROL=ignoredups:erasedups:ignorespace -# Use empty string for unlimited history -export HISTSIZE= export HISTFILESIZE= +export HISTSIZE= export HISTTIMEFORMAT='%y-%m-%d %T λ ' - export RIPGREP_CONFIG_PATH="${XDG_CONFIG_HOME}/ripgrep/config" -# make less more friendly for non-text input files, see lesspipe(1) -[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" - -# enable color support of ls and also add handy aliases -if [ -x /usr/bin/dircolors ]; then - test -r ~/.dircolors && (eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)") -fi - -if [ "$TERM" == xterm ]; then - export TERM=xterm-256color -fi diff --git a/bash/functions b/bash/functions index 6a1b8dc..4e42fc5 100644 --- a/bash/functions +++ b/bash/functions @@ -4,7 +4,7 @@ function min-jpg { tmpfile="$(mktemp)" ogfile="$1" jpegtran -optimize -perfect -outfile "$tmpfile" "$ogfile" - mv "$tmpfile" $ogfile + mv "$tmpfile" "$ogfile" } function min-png { @@ -22,19 +22,9 @@ function add-date-prefix { DIR=$(dirname "$1") FILE=$(basename "$1") DATE=$(date -r "$1" +"%F") - mv "$1" "$DIR/$DATE_$FILE" + mv "$1" "$DIR/${DATE}_${FILE}" } function get-bitrate { exiftool -AudioBitrate "$1" | awk '{print $4}' } - -function deepgrep { - find . \ - -type d -name node_modules -prune -o \ - -type d -name .git -prune -o \ - -type f \ - -not -name "*.swp" \ - -not -name "*.pyc" \ - -exec grep --with-filename --color "$@" {} \; -} diff --git a/bash/path b/bash/path index 5515601..bd99091 100644 --- a/bash/path +++ b/bash/path @@ -2,7 +2,7 @@ function add-path { dir="$1" - if [[ $PATH =~ "$dir" ]]; then + if [[ $PATH =~ $dir ]]; then return fi if [[ -d $dir ]]; then @@ -12,7 +12,7 @@ function add-path { function prefix-path { dir="$1" - if [[ $PATH =~ "$dir" ]]; then + if [[ $PATH =~ $dir ]]; then return fi if [[ -d $dir ]]; then diff --git a/bash/prompt b/bash/prompt index 22d25a8..056562a 100644 --- a/bash/prompt +++ b/bash/prompt @@ -1,11 +1,19 @@ #!/usr/bin/env bash +# Reset +color_off='\e[0m' # Text Reset + +green='\e[0;32m' # Green +yellow='\e[0;33m' # Yellow +blue='\e[0;34m' # Blue +purple='\e[0;35m' # Purple + function _hostname-color { case "$(whoami)" in - william) echo $blue;; - buddy) echo $blue;; - root) echo $bred;; - *) echo $purple;; + william) echo "$blue";; + buddy) echo "$blue";; + root) echo "$bred";; + *) echo "$purple";; esac } @@ -29,15 +37,82 @@ function parse_git_status { return fi - if [[ $(git status 2> /dev/null | grep -E "working tree|directory clean" | wc -l) -eq 0 ]]; then + if [[ $(git status 2> /dev/null | grep -c "working tree|directory clean") -eq 0 ]]; then echo ' ∓' fi } function _hostname-show { - hostname -s | tr '[A-Z]' '[a-z]' + hostname -s | tr ':A-Z:' ':a-z:' } function parse_git_branch { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' } + +# Regular Colors +#black='\e[0;30m' # Black +#red='\e[0;31m' # Red +#cyan='\e[0;36m' # Cyan +#white='\e[0;37m' # White + +# Bold +bblack='\e[1;30m' # Black +bred='\e[1;31m' # Red +#bgreen='\e[1;32m' # Green +#byellow='\e[1;33m' # Yellow +#bblue='\e[1;34m' # Blue +#bpurple='\e[1;35m' # Purple +#bcyan='\e[1;36m' # Cyan +#bwhite='\e[1;37m' # White + +# Underline +#ublack='\e[4;30m' # Black +#ured='\e[4;31m' # Red +#ugreen='\e[4;32m' # Green +#uyellow='\e[4;33m' # Yellow +#ublue='\e[4;34m' # Blue +#upurple='\e[4;35m' # Purple +#ucyan='\e[4;36m' # Cyan +#uwhite='\e[4;37m' # White + +# Background +#on_black='\e[40m' # Black +#on_red='\e[41m' # Red +#on_green='\e[42m' # Green +#on_yellow='\e[43m' # Yellow +#on_blue='\e[44m' # Blue +#on_purple='\e[45m' # Purple +#on_cyan='\e[46m' # Cyan +#on_white='\e[47m' # White + +# High Intensty +#iblack='\e[0;90m' # Black +#ired='\e[0;91m' # Red +#igreen='\e[0;92m' # Green +#iyellow='\e[0;93m' # Yellow +#iblue='\e[0;94m' # Blue +#ipurple='\e[0;95m' # Purple +#icyan='\e[0;96m' # Cyan +#iwhite='\e[0;97m' # White + +# Bold High Intensty +#biblack='\e[1;90m' # Black +#biRed='\e[1;91m' # Red +#biGreen='\e[1;92m' # Green +#biYellow='\e[1;93m' # Yellow +#biBlue='\e[1;94m' # Blue +#biPurple='\e[1;95m' # Purple +#biCyan='\e[1;96m' # Cyan +#biWhite='\e[1;97m' # White + +# High Intensty backgrounds +#on_iblack='\e[0;100m' # Black +#on_ired='\e[0;101m' # Red +#on_igreen='\e[0;102m' # Green +#on_iyellow='\e[0;103m' # Yellow +#on_iblue='\e[0;104m' # Blue +#on_ipurple='\e[10;95m' # Purple +#on_icyan='\e[0;106m' # Cyan +#on_iwhite='\e[0;107m' # White + diff --git a/bashrc b/bashrc index d440dde..2f8bfae 100644 --- a/bashrc +++ b/bashrc @@ -16,14 +16,37 @@ fi source-file /etc/bash_completion source-file ~/.bash/environment -source-file ~/.bash/colors source-file ~/.bash/aliases source-file ~/.bash/functions source-file ~/.bash/path source-file ~/.bash/prompt -#source-file ~/.bash/ensure-ssh-agent source-file ~/.bash/completion source-file ~/opt/bash/env -source-file ~/go/bin unset -f source-file + +# append to the history file, don't overwrite it +shopt -s histappend + +# check the window size after each command and, if necessary, +# update the values of LINES and COLUMNS. +shopt -s checkwinsize + +# Disable capslock +if [[ -x $(which setxkbmap) ]]; then + if [[ $(uname) == Linux ]]; then + setxkbmap -option ctrl:nocaps + fi +fi + +# make less more friendly for non-text input files, see lesspipe(1) +[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" + +# enable color support of ls and also add handy aliases +if [ -x /usr/bin/dircolors ]; then + test -r ~/.dircolors && (eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)") +fi + +if [ "$TERM" == xterm ]; then + export TERM=xterm-256color +fi