From aabb888752f19fe18b2f7eb2f02c6b7c820747cb Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Mon, 31 Dec 2018 23:28:18 -0800 Subject: [PATCH] clean up bash config --- bash/aliases | 69 +++++++++++++----------------------------------- bash/environment | 36 ++++++++++++------------- bash/functions | 32 +++++++++------------- bash/path | 36 +++++++++++++------------ bashrc | 68 +++++++++++++---------------------------------- 5 files changed, 85 insertions(+), 156 deletions(-) diff --git a/bash/aliases b/bash/aliases index bee273c..8119351 100644 --- a/bash/aliases +++ b/bash/aliases @@ -1,50 +1,32 @@ #!/usr/bin/env bash -pods_dir='~/podcasts' +music_dir='~/music' +desktop_dir='~/desktop' +docs_dir='~/documents' # Aliases for OS X -if [[ `uname` == 'Darwin' ]]; then - alias ls='ls -G' - alias grep='grep --color' - alias fgrep='fgrep --color' - alias egrep='egrep --color' - +if [[ $(uname) == Darwin ]]; then music_dir='~/Music' desktop_dir='~/Desktop' docs_dir='~/Documents' -else - music_dir='~/music' - desktop_dir='~/desktop' - docs_dir='~/documents' - - # linux only alias - alias push-to-player="rsync -recursive --verbose --times --modify-window=1 --delete $pods_dir/ `mount -l | awk '/podcasts/ {print $3}'`/podcast/" -fi -if [[ `uname` == 'FreeBSD' ]]; then - alias ls='ls -G' fi -if [[ `uname` == 'FreeBSD' ]]; then - alias ls='ls -G' -fi - -# 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)" - alias ls='ls --color=auto' - alias dir='dir --color=auto' - alias vdir='vdir --color=auto' - alias grep='grep --color=auto' - alias fgrep='fgrep --color=auto' - alias egrep='egrep --color=auto' -fi +alias ls='ls --color=auto' +alias dir='dir --color=auto' +alias vdir='vdir --color=auto' +alias grep='grep --color=auto' +alias fgrep='fgrep --color=auto' +alias egrep='egrep --color=auto' -alias dash-v1='cd ~/code/insight-platform && ~/src/grails-1.2.2/bin/grails run-app -https -Xms800m -Xmx1000m -XX:PermSize=200m' - -# Fix vagrant up errors on Mavericks -# http://davidwalsh.name/fixing-vagrant-errors -alias fix-vagrant='sudo /Library/StartupItems/VirtualBox/VirtualBox restart' +# Move around to common locations +alias desktop="cd $desktop_dir" +alias podcasts="cd ~/podcasts" +alias code='cd ~/code/ ' +alias music="cd $music_dir" +alias documents="cd $docs_dir" -alias docker-env='eval $(docker-machine env default)' +unset -v music_dir +unset -v desktop_dir +unset -v docs_dir # Some common aliases alias ll='ls -alF' @@ -74,16 +56,3 @@ alias numfiles='find . -maxdepth 1 -type f | wc -l' alias deepgrep='find . -type f -not -name "*.swp" -not -name "*.pyc" | sed "s/$/\"/g" | sed "s/^/\"/g" | xargs grep --color ' # Show list of git branches alias git-br='for k in `git branch|perl -pe s/^..//`; do echo -e ` git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k|head -n 1`\\t$k;done|sort -r' - -alias sync-pods="rsync --archive --verbose --compress --delete nas:~/podcasts/ $pods_dir" - -# Move around to common locations -alias desktop="cd $desktop_dir" -alias podcasts="cd $pods_dir" -alias code='cd ~/code/ ' -alias music="cd $music_dir" -alias documents="cd $docs_dir" - -# Will add these scripts later -#alias podcasts-play-playlist="cd $pods_dir && mkpodcastplaylist ./ > pods.m3u && vlc pods.m3u 2>/dev/null &" - diff --git a/bash/environment b/bash/environment index 7c0f2ed..17339da 100644 --- a/bash/environment +++ b/bash/environment @@ -1,43 +1,41 @@ #!/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 +if [[ -x $(which setxkbmap) ]]; then + if [[ $(uname) == Linux ]]; then setxkbmap -option ctrl:nocaps fi fi +export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" +export EDITOR='vim' + # don't put duplicate lines in the history. See bash(1) for more options # ... or force ignoredups and ignorespace export HISTCONTROL=ignoredups:erasedups:ignorespace - -# append to the history file, don't overwrite it -shopt -s histappend - # Use empty string for unlimited history export HISTSIZE= export HISTFILESIZE= export HISTTIMEFORMAT='%y-%m-%d %T λ ' -export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" - -# check the window size after each command and, if necessary, -# update the values of LINES and COLUMNS. -shopt -s checkwinsize # make less more friendly for non-text input files, see lesspipe(1) [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" -if [ "$TERM" == "xterm" ]; then - export TERM=xterm-256color +# 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 [[ $(uname) == 'Darwin' ]]; then - export BS_OS='osx' -elif [[ $(uname) == 'Linux' ]]; then - export BS_OS='linux' +if [ "$TERM" == xterm ]; then + export TERM=xterm-256color fi -export EDITOR='vim' - [[ -f ~/.nvm/nvm.sh ]] && source ~/.nvm/nvm.sh [[ -r $NVM_DIR/bash_completion ]] && source $NVM_DIR/bash_completion diff --git a/bash/functions b/bash/functions index 992a3d0..a1dd6b1 100644 --- a/bash/functions +++ b/bash/functions @@ -1,19 +1,14 @@ #!/usr/bin/env bash -# Taken from: http://www.commandlinefu.com/commands/view/4873/google-spell-checker -function spellcheck () { - typeset y=$@;curl -sd "$y" https://www.google.com/tbproxy/spell|sed -n '/s="[0-9]"/{s/<[^>]*>/ /g;s/\t/ /g;s/ *\(.*\)/Suggestions: \1\n/g;p}'|tee >(grep -Eq '.*'||echo -e "OK"); -} - function min-jpg { - tmpfile=`mktemp` + tmpfile=$(mktemp) ogfile="$1" jpegtran -optimize -perfect -outfile $tmpfile $ogfile mv $tmpfile $ogfile } function min-png { - tmpfile=`mktemp` + tmpfile=$(mktemp) ogfile="$1" pngcrush -rem alla -reduce -brute $ogfile $tmpfile mv $tmpfile $ogfile @@ -34,32 +29,29 @@ function parse_git_branch { } function get-create-date { - date=`date -r "$1" +"%F"` - echo $date + date -r "$1" +"%F" } function add-date-prefix { - DIR=`dirname "$1"` - FILE=`basename "$1"` - DATE=`date -r "$1" +"%F"` - + DIR=$(dirname "$1") + FILE=$(basename "$1") + DATE=$(date -r "$1" +"%F") mv "$1" "$DIR/$DATE_$FILE" } function get-bitrate { - echo `exiftool -AudioBitrate "$1" | awk '{print $4}'`": $1" + exiftool -AudioBitrate "$1" | awk '{print $4}' } function _hostname-color { - case `whoami` in - 'bsandidge') echo $blue;; - 'buddy') echo $blue;; - 'root') echo $bred;; - *) echo $purple;; + case "$(whoami)" in + william) echo $blue;; + buddy) echo $blue;; + root) echo $bred;; + *) echo $purple;; esac } function _hostname-show { hostname -s | tr '[A-Z]' '[a-z]' } - diff --git a/bash/path b/bash/path index 48099c1..b5ceb69 100644 --- a/bash/path +++ b/bash/path @@ -1,6 +1,6 @@ #!/usr/bin/env bash -function _add-path { +function add-path { dir="$1" if [[ $PATH =~ "$dir" ]]; then return @@ -10,19 +10,21 @@ function _add-path { fi } -_add-path ~/.cargo/bin -_add-path ~/go/bin -_add-path /var/lib/gems/1.8/bin -_add-path /Library/Frameworks/Python.framework/Versions/2.7/bin -_add-path ~/Library/Python/2.7/bin -_add-path ~/.rvm/bin -_add-path ~/opt/bin -_add-path /usr/local/mysql/bin -_add-path /opt/vertica/bin -_add-path /opt/local/bin -_add-path /opt/local/sbin -_add-path ~/bin -_add-path /usr/local/go/bin -_add-path ~/.bin -_add-path ~/opt/depot_tools -_add-path ~/.yarn/bin +add-path ~/.cargo/bin +add-path ~/go/bin +add-path /var/lib/gems/1.8/bin +add-path /Library/Frameworks/Python.framework/Versions/2.7/bin +add-path ~/Library/Python/2.7/bin +add-path ~/.rvm/bin +add-path ~/opt/bin +add-path /usr/local/mysql/bin +add-path /opt/vertica/bin +add-path /opt/local/bin +add-path /opt/local/sbin +add-path ~/bin +add-path /usr/local/go/bin +add-path ~/.bin +add-path ~/opt/depot_tools +add-path ~/.yarn/bin + +unset -f _add-path diff --git a/bashrc b/bashrc index 7069050..f512001 100644 --- a/bashrc +++ b/bashrc @@ -1,53 +1,21 @@ # If not running interactively, don't do anything [ -z "$PS1" ] && return -if [ -f ~/.bash/environment ]; then - source ~/.bash/environment -fi - -if [ -f ~/.bash/path ]; then - source ~/.bash/path -fi - -if [ -f ~/.bash/colors ]; then - source ~/.bash/colors -fi - -if [ -f ~/.bash/functions ]; then - source ~/.bash/functions -fi - -if [ -f ~/.bash/aliases ]; then - source ~/.bash/aliases -fi - -if [ -f ~/.bash/git-flow-completion ]; then - source ~/.bash/git-flow-completion -fi - -if [ -f ~/opt/bash/env ]; then - source ~/opt/bash/env -fi - -# enable programmable completion features (you don't need to enable -# this, if it's already enabled in /etc/bash.bashrc and /etc/profile -# sources /etc/bash.bashrc). -if [ -f /etc/bash_completion ] && ! shopt -oq posix; then - source /etc/bash_completion -fi - -if [ -f /opt/local/etc/profile.d/bash_completion.sh ]; then - source /opt/local/etc/profile.d/bash_completion.sh -fi - -if [ -f /etc/bashrc ]; then - source /etc/bashrc -fi - -if [ -f ~/.bash/prompt ]; then - source ~/.bash/prompt -fi - -if [ -f ~/.bash/direnv-hook ]; then - source ~/.bash/direnv-hook -fi +function source-file { + file="$1" + if [[ -f "$file" ]]; then + . "$file" + fi +} + +source-file /etc/bash_completion +source-file ~/.bash/colors +source-file ~/.bash/aliases +source-file ~/.bash/functions +source-file ~/.bash/git-flow-completion +source-file ~/.bash/path +source-file ~/.bash/environment +source-file ~/.bash/prompt +source-file ~/opt/bash/env + +unset -f source-file