From db5739614eeab8882432924d1526ebc07ff271c1 Mon Sep 17 00:00:00 2001 From: Bodaniel Jeanes Date: Wed, 30 Jun 2010 14:54:06 +1000 Subject: [PATCH] Major refactoring of ZSH and Bash dot-files. * Theme is now set for both shells from same file so they should always be as similar as possible. * Removed terminal functions (for doing silly things like moving/resizing the Terminal.app window) which I never used * Not using ZSH color module (so that I can have some level of compatibility with bash for prompt etc) --- bash/config.sh | 18 +++-------- bash/terminal | 47 ---------------------------- shell/aliases.sh | 25 +-------------- shell/common.sh | 9 +++--- shell/exports.sh | 22 ++----------- shell/osx.sh | 5 +-- shell/prompt.sh | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ zsh/theme.zsh | 26 ---------------- zsh/zshrc | 12 ++------ 9 files changed, 96 insertions(+), 148 deletions(-) delete mode 100644 bash/terminal create mode 100644 shell/prompt.sh delete mode 100644 zsh/theme.zsh diff --git a/bash/config.sh b/bash/config.sh index 8e0af7f..605bd36 100644 --- a/bash/config.sh +++ b/bash/config.sh @@ -1,16 +1,4 @@ -alias reload="source ~/.bashrc" - -export PS1="\w ♪ " - -if [ $system_name == 'Darwin' ]; then - source $DOT_FILES/bash/terminal -fi - -if [ -f /etc/bash_completion ]; then - . /etc/bash_completion -# else - # . $DOT_FILES/bash/bash_completion -fi +[[ -f /etc/bash_completion ]] && source /etc/bash_completion # readline settings bind "set completion-ignore-case on" @@ -22,4 +10,6 @@ shopt -s histappend shopt -s cdable_vars shopt -s globstar 2>/dev/null # Bash 4 and above only -complete -C $DOT_FILES/bash/rake-completion.rb -o default rake} \ No newline at end of file +complete -C $DOT_FILES/bash/rake-completion.rb -o default rake} + +alias reload="source ~/.bashrc" \ No newline at end of file diff --git a/bash/terminal b/bash/terminal deleted file mode 100644 index 7f864b6..0000000 --- a/bash/terminal +++ /dev/null @@ -1,47 +0,0 @@ -# Minimise terminal window to Dock -function mintw() { printf "\e[2t"; return 0; } - -# Send Terminal window to background -function bgtw() { printf "\e[6t"; return 0; } - -function hidetw() { - /usr/bin/osascript -e 'tell application "System Events" to set visible of some item of ( get processes whose name = "Terminal" ) to false' - return 0 -} - -# positive integer test (including zero) -function positive_int() { return $(test "$@" -eq "$@" > /dev/null 2>&1 && test "$@" -ge 0 > /dev/null 2>&1); } - -# move the Terminal window -function mvtw() { - if [[ $# -eq 2 ]] && $(positive_int "$1") && $(positive_int "$2"); then - printf "\e[3;${1};${2};t" - return 0 - fi - return 1 -} - -# resize the Terminal window -function sizetw() { - if [[ $# -eq 2 ]] && $(positive_int "$1") && $(positive_int "$2"); then - printf "\e[8;${1};${2};t" - /usr/bin/clear - return 0 - fi - return 1 -} - -# full screen -function fullscreen() { printf "\e[3;0;0;t\e[8;0;0t"; /usr/bin/clear; return 0; } - -# default screen -function defaultscreen() { printf "\e[8;35;150;t"; printf "\e[3;300;240;t"; /usr/bin/clear; return 0; } - -# max columns -function maxc() { printf "\e[3;0;0;t\e[8;50;0t"; /usr/bin/clear; return 0; } - -# max rows -function maxr() { printf "\e[3;0;0;t\e[8;0;100t"; /usr/bin/clear; return 0; } - -# show number of lines & columns -function lc() { printf "lines: $(/usr/bin/tput lines)\ncolums: $(/usr/bin/tput cols)\n"; return 0; } \ No newline at end of file diff --git a/shell/aliases.sh b/shell/aliases.sh index fec7fd0..871491c 100644 --- a/shell/aliases.sh +++ b/shell/aliases.sh @@ -67,27 +67,4 @@ function extract() { else echo "'$1' is not a valid file" fi -} - -if [ `uname -s` = "Darwin" ]; then - function prompt_pwd() { - if [ "$PWD" != "$HOME" ]; then - printf "%s" `echo $PWD|sed -e 's|/private||' -e "s|^$HOME|~|" -e 's-/\(\.\{0,1\}[^/]\)\([^/]*\)-/\1-g'` - echo $PWD|sed -e 's-.*/\.\{0,1\}[^/]\([^/]*$\)-\1-' - else - echo '~' - fi - } -else # defined two for diff systems because Fish did (not entirely sure why) - function prompt_pwd() { - case "$PWD" in - $HOME) - echo '~' - ;; - *) - printf "%s" `echo $PWD|sed -e "s|^$HOME|~|" -e 's-/\(\.\{0,1\}[^/]\)\([^/]*\)-/\1-g'` - echo $PWD|sed -n -e 's-.*/\.\{0,1\}.\([^/]*\)-\1-p' - ;; - esac - } -fi \ No newline at end of file +} \ No newline at end of file diff --git a/shell/common.sh b/shell/common.sh index 05c6db7..533c9a6 100644 --- a/shell/common.sh +++ b/shell/common.sh @@ -1,11 +1,12 @@ -PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/local/mongodb/bin:/usr/local/pgsql/bin:/usr/X11/bin:/opt/local/bin +PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/local/mongodb/bin:/usr/local/pgsql/bin:/usr/X11/bin:/opt/local/bin:${PATH}" CDPATH=".:${HOME}" +VCPROMPT="${HOME}/.config/misc/vcprompt.py" +source $DOT_FILES/$CURRENT_SHELL/config.*sh source $DOT_FILES/shell/exports.sh source $DOT_FILES/shell/aliases.sh source $DOT_FILES/shell/save-directory.sh +source $DOT_FILES/shell/prompt.sh source $DOT_FILES/git/git.sh -[[ `uname -s` == 'Darwin' ]] && source $DOT_FILES/shell/osx.sh - -VCPROMPT=~/.config/misc/vcprompt.py \ No newline at end of file +[[ `uname -s` == 'Darwin' ]] && source $DOT_FILES/shell/osx.sh \ No newline at end of file diff --git a/shell/exports.sh b/shell/exports.sh index 9194d95..c92f474 100644 --- a/shell/exports.sh +++ b/shell/exports.sh @@ -2,7 +2,8 @@ export PATH="/usr/local/mysql/bin/:$PATH" export PATH="/opt/local/bin:/opt/local/sbin:$PATH" export PATH="$PATH:/usr/local/jruby/bin" -# Use single quotes here to lazy evaluate the $EDITOR variable +# Use single quotes here to lazy evaluate the $EDITOR variable (as it changes later if on OS X) +export EDITOR='nano -w' export GEM_OPEN_EDITOR='$EDITOR' export GIT_EDITOR='$EDITOR' export VISUAL='$EDITOR' @@ -10,27 +11,8 @@ export VISUAL='$EDITOR' export IRBRC="$HOME/.irbrc" export JEWELER_OPTS="--rspec --gemcutter --rubyforge --reek --roodi" -export COLOR_NC='\e[0m' # No Color -export COLOR_WHITE='\e[1;37m' -export COLOR_BLACK='\e[0;30m' -export COLOR_BLUE='\e[0;34m' -export COLOR_LIGHT_BLUE='\e[1;34m' -export COLOR_GREEN='\e[0;32m' -export COLOR_LIGHT_GREEN='\e[1;32m' -export COLOR_CYAN='\e[0;36m' -export COLOR_LIGHT_CYAN='\e[1;36m' -export COLOR_RED='\e[0;31m' -export COLOR_LIGHT_RED='\e[1;31m' -export COLOR_PURPLE='\e[0;35m' -export COLOR_LIGHT_PURPLE='\e[1;35m' -export COLOR_BROWN='\e[0;33m' -export COLOR_YELLOW='\e[1;33m' -export COLOR_GRAY='\e[0;30m' -export COLOR_LIGHT_GRAY='\e[0;37m' - export TERM=xterm-color export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32' export CLICOLOR=1 export HISTSIZE=1000000 - diff --git a/shell/osx.sh b/shell/osx.sh index 0a6e077..904e2cb 100644 --- a/shell/osx.sh +++ b/shell/osx.sh @@ -6,8 +6,7 @@ alias o='open .' # replacement netstat cmd to find ports used by apps on OS X alias netstat="sudo lsof -i -P" -alias pubkey='pubkey | pbcopy && echo "Keys copied to clipboard"' - +alias pubkey="cat $HOME/.ssh/*.pub | pbcopy && echo 'Keys copied to clipboard'" alias hidefile='/usr/bin/SetFile -a "V"' alias showfile='/usr/bin/SetFile -a "v"' @@ -21,8 +20,6 @@ function osinfo() { echo "${x1} - ${x2} - ${x3} - ${x4}" } - - function tab() { osascript 2>/dev/null </dev/null 2>/dev/null && echo '±' && return + hg root >/dev/null 2>/dev/null && echo '☿' && return + # echo '○' + echo '♪' +} + +function prompt_color() { + if [ "$USER" = "root" ]; then + echo red + else + if [ -n "$SSH_TTY" ]; then + echo blue + else + echo green + fi + fi +} + +function prompt_vcs_if_bash() { + if [ $CURRENT_SHELL = 'bash' ]; then + local vcs="$(eval echo $RPS1)" + [[ "$vcs" != "" ]] && echo " $vcs" + fi +} + +RPS1='$(${VCPROMPT} -f $(color red)‹%b:%h›$(color reset))' +PS1="\$(color blue)\$(prompt_pwd)\$(prompt_vcs_if_bash) \$(color \$(prompt_color))\$(prompt_char)\$(color reset) " diff --git a/zsh/theme.zsh b/zsh/theme.zsh deleted file mode 100644 index 9b84d8f..0000000 --- a/zsh/theme.zsh +++ /dev/null @@ -1,26 +0,0 @@ -function prompt_color() { - if [ "$USER" = "root" ]; then - echo "red" - else - if [ -n "$SSH_TTY" ]; then - echo "blue" - else - echo "green" - fi - fi -} - -function prompt_char { - git branch >/dev/null 2>/dev/null && echo '±' && return - hg root >/dev/null 2>/dev/null && echo '☿' && return - # echo '○' - echo '♪' -} - -# Prompts -ZSH_THEME_VCS_PROMPT_PREFIX="%{$fg[red]%}‹" -ZSH_THEME_VCS_PROMPT_SUFFIX="›%{$reset_color%}" -ZSH_THEME_VCS_PROMPT_FORMAT="${ZSH_THEME_VCS_PROMPT_PREFIX}%b:%h${ZSH_THEME_VCS_PROMPT_SUFFIX}" - -PS1='%{$fg[blue]%}$(prompt_pwd)%{$reset_color%} %{$fg[$(prompt_color)]%}$(prompt_char)%{$reset_color%} ' -RPS1='$(${VCPROMPT} -f ${ZSH_THEME_VCS_PROMPT_FORMAT})' diff --git a/zsh/zshrc b/zsh/zshrc index d1bf23c..f860e8a 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -1,14 +1,11 @@ -export CURRENT_SHELL=`which zsh` +export CURRENT_SHELL="zsh" export DOT_FILES=$HOME/.config -# Common functionality between Zsh and Bash -source $DOT_FILES/shell/common.sh - # Install and load oh-my-zsh source $DOT_FILES/zsh/oh-my-zsh.zsh -# Extra ZSH configuration -source $DOT_FILES/zsh/config.zsh +# Common functionality between Zsh and Bash +source $DOT_FILES/shell/common.sh # Rake completion source $DOT_FILES/zsh/completions.zsh @@ -16,8 +13,5 @@ source $DOT_FILES/zsh/completions.zsh # Rake completion source $DOT_FILES/zsh/rake_completion.zsh -# My custom theme -source $DOT_FILES/zsh/theme.zsh - # RVM [[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm \ No newline at end of file