Просмотр исходного кода

Merge branch 'master' of code.parsleygardens.net:cinaeco/dotfiles

cinaeco 13 лет назад
Родитель
Сommit
a858ac8a02
4 измененных файлов с 97 добавлено и 52 удалено
  1. 28 34
      RUNME
  2. 40 18
      zsh/oh-my-zsh-custom/cinaeco.zsh-theme
  3. 27 0
      zsh/oh-my-zsh-custom/plugins/vi-mode/vi-mode.plugin.zsh
  4. 2 0
      zsh/zshrc

+ 28 - 34
RUNME

@@ -6,40 +6,34 @@
 # A lot of this extra knowledge courtesy of vimcasts.org!
 # A lot of this extra knowledge courtesy of vimcasts.org!
 
 
 # Make a known_hosts file if none, otherwise zsh throws an error for our .zshrc
 # Make a known_hosts file if none, otherwise zsh throws an error for our .zshrc
-echo "Checking for known_hosts:"
 if test -f ~/.ssh/known_hosts; then
 if test -f ~/.ssh/known_hosts; then
-  echo " -> Found"
+  echo "known_hosts found..."
 else
 else
-  echo " -> Not Found"
   mkdir -p ~/.ssh
   mkdir -p ~/.ssh
   touch ~/.ssh/known_hosts
   touch ~/.ssh/known_hosts
-  echo " -> Created ~/.ssh/known_hosts"
+  echo "known_hosts created (blank)..."
 fi
 fi
 
 
 # Ack for this user (perl 5.8.8 or higher on system)
 # Ack for this user (perl 5.8.8 or higher on system)
 # Curl may need to have proxy settings
 # Curl may need to have proxy settings
-echo "Checking for ack in ~/bin:"
 if test -f ~/bin/ack; then
 if test -f ~/bin/ack; then
-  echo " -> Found"
+  echo "ack found..."
 else
 else
-  echo " -> Not Found"
   mkdir -p ~/bin
   mkdir -p ~/bin
   curl http://betterthangrep.com/ack-standalone > ~/bin/ack
   curl http://betterthangrep.com/ack-standalone > ~/bin/ack
   chmod 0755 ~/bin/ack
   chmod 0755 ~/bin/ack
-  echo " -> Installed ~/bin/ack from betterthangrep.com"
+  echo "ack installed from betterthangrep.com..."
 fi
 fi
 
 
 # color for git! Some machines don't have it.
 # color for git! Some machines don't have it.
-echo "Setting up git colour and editor:"
 git config --global color.ui true
 git config --global color.ui true
 git config --global core.editor "vim"
 git config --global core.editor "vim"
-echo " -> Done"
+echo "git colour and editor setup..."
 
 
 # This repository has vim plugins as submodules, so initialise and clone them
 # This repository has vim plugins as submodules, so initialise and clone them
-echo "Getting dotfiles submodules:"
 git submodule init
 git submodule init
 git submodule update
 git submodule update
-echo " -> Done"
+echo "dotfiles submodules done..."
 
 
 # Add more vim plugins from this dotfiles directory, like so:
 # Add more vim plugins from this dotfiles directory, like so:
 #     git submodule add git://github.com/tpope/module.git vim/bundle/module
 #     git submodule add git://github.com/tpope/module.git vim/bundle/module
@@ -47,41 +41,41 @@ echo " -> Done"
 # Apart from updating plugins individually, you can update all submodules
 # Apart from updating plugins individually, you can update all submodules
 #     git submodule foreach git pull origin master
 #     git submodule foreach git pull origin master
 
 
-# SSH Config
-echo "Symlinking for ssh:"
-ln -s ../dotfiles/ssh/config ~/.ssh/config
-echo " -> Done"
 
 
-# Vim
-echo "Symlinking for vim:"
-if test -d ~/.vim; then
-  echo " -> .vim folder exists"
-else
-  ln -s dotfiles/vim/ ~/.vim
-fi
-ln -s dotfiles/vim/vimrc ~/.vimrc
-mkdir ~/.vimundo # persistent undo directory
-echo " -> Done"
+#
+# Thanks to: https://github.com/dangerous/dotfiles
+# for cleaner way of handling symlinking
+#
+BACKUP_DIR="/tmp/$(date)"
+mkdir "$BACKUP_DIR"
 
 
 # Zsh
 # Zsh
-echo "Symlinking for zsh:"
+mv ~/.zshrc "$BACKUP_DIR"
 ln -s dotfiles/zsh/zshrc ~/.zshrc
 ln -s dotfiles/zsh/zshrc ~/.zshrc
+mv ~/.zshenv "$BACKUP_DIR"
 ln -s dotfiles/zsh/zshenv ~/.zshenv
 ln -s dotfiles/zsh/zshenv ~/.zshenv
-echo " -> Done"
+
+# Vim
+mv ~/.vim "$BACKUP_DIR"
+ln -s dotfiles/vim ~/.vim
+mv ~/.vimrc "$BACKUP_DIR"
+ln -s dotfiles/vim/vimrc ~/.vimrc
+mkdir -p ~/.vimundo # persistent undo directory
+
+# SSH Config
+mv ~/.ssh/config "$BACKUP_DIR"
+ln -s ../dotfiles/ssh/config ~/.ssh/config
 
 
 # Pentadactyl
 # Pentadactyl
-echo "Symlinking for pentadactyl:"
+mv ~/.pentadactylrc "$BACKUP_DIR"
 ln -s dotfiles/pentadactyl/pentadactylrc ~/.pentadactylrc
 ln -s dotfiles/pentadactyl/pentadactylrc ~/.pentadactylrc
-echo " -> Done"
 
 
 # Screen
 # Screen
-echo "Symlinking for gnu screen:"
+mv ~/.screenrc "$BACKUP_DIR"
 ln -s dotfiles/screen/screenrc ~/.screenrc
 ln -s dotfiles/screen/screenrc ~/.screenrc
-echo " -> Done"
 
 
 # Nethack
 # Nethack
-echo "Symlinking for nethack:"
+mv ~/.nethackrc "$BACKUP_DIR"
 ln -s dotfiles/nethack/nethackrc ~/.nethackrc
 ln -s dotfiles/nethack/nethackrc ~/.nethackrc
-echo " -> Done"
 
 
 echo "Setup complete!"
 echo "Setup complete!"

+ 40 - 18
zsh/oh-my-zsh-custom/cinaeco.zsh-theme

@@ -1,11 +1,32 @@
 ## Override the default `git_prompt_info` function
 ## Override the default `git_prompt_info` function
+## We decide if we show nothing, status with no branch (like in submodules) or
+## with a branch using regex comparisons. Is there a better way?
 function git_prompt_info() {
 function git_prompt_info() {
-  ref=$(git symbolic-ref HEAD 2> /dev/null) || return
-  echo "$(git_prompt_status) $(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
+  ref=$(git symbolic-ref HEAD 2>&1)
+  [[ $ref =~ "Not a git" ]] && return
+  [[ $ref =~ "not a symbolic" ]] && echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_repository):%{$fg[red]%}no branch$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX $(git_prompt_status)" && return
+  echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_repository):$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX $(git_prompt_status)"
+}
 
 
+## Override the default `current_repository` function
+## We don't need to test if HEAD is a symbolic ref - that gets controlled in
+## git_prompt_info(). Unlike `current_branch` there are no oh-my-zsh shortcuts
+## that will be broken if we don't test for this.
+##
+## also, the built-in function cannot cope with non-ssh repos because it relies
+## on there being a ':' before the repo name
+function current_repository() {
+  echo $(git remote -v | head -1 | grep -o '[^/]*\.git' | sed 's/.git//')
 }
 }
 
 
+ZSH_THEME_GIT_PROMPT_PREFIX="[git:"
+ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}"
+ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%}"
+ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}"
+
 ## Override the default `git_prompt_status` function
 ## Override the default `git_prompt_status` function
+## This one will try to print a symbol for each change listed in git status.
+## The old version only listed if each type existed or not.
 git_prompt_status() {
 git_prompt_status() {
   INDEX=$(git status -s 2> /dev/null)
   INDEX=$(git status -s 2> /dev/null)
   STATUS=""
   STATUS=""
@@ -40,7 +61,14 @@ git_prompt_status() {
   echo $STATUS
   echo $STATUS
 }
 }
 
 
-# Using precmd instead of having a multiline prompt reduces the number of 
+ZSH_THEME_GIT_PROMPT_ADDED="%{$FG[082]%}+%{$reset_color%}"
+ZSH_THEME_GIT_PROMPT_MODIFIED="%{$FG[160]%}+%{$reset_color%}"
+ZSH_THEME_GIT_PROMPT_DELETED="%{$FG[160]%}x%{$reset_color%}"
+ZSH_THEME_GIT_PROMPT_RENAMED="%{$FG[220]%}>%{$reset_color%}"
+ZSH_THEME_GIT_PROMPT_UNMERGED="%{$FG[082]%}u%{$reset_color%}"
+ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$FG[160]%}?%{$reset_color%}"
+
+# Using precmd instead of having a multiline prompt reduces the number of
 # `%{` and `%}` escape sequences needed. Actions like changing mode in vi-mode
 # `%{` and `%}` escape sequences needed. Actions like changing mode in vi-mode
 # and using tab completion need the escapes to know the right number of printed
 # and using tab completion need the escapes to know the right number of printed
 # characters in the prompt or rprompt, otherwise, they will offset displayed
 # characters in the prompt or rprompt, otherwise, they will offset displayed
@@ -50,25 +78,19 @@ git_prompt_status() {
 # new prompt not based on precmd, found that prompt renders half a second faster
 # new prompt not based on precmd, found that prompt renders half a second faster
 # which is much less annoying over prolonged usage. Have moved git status to the
 # which is much less annoying over prolonged usage. Have moved git status to the
 # right prompt. Less exciting, but more functional. Drats.
 # right prompt. Less exciting, but more functional. Drats.
+#
+# UPDATE2: have found a modification to the vi-mode plugin that allows for
+# better catering for multiline prompts, without overwriting history lines.
+# Refer to custom directory for more details
 #function precmd() {}
 #function precmd() {}
 
 
 ## Set tab title to hostname
 ## Set tab title to hostname
 print -Pn "\e]1;`hostname | cut -d. -f1`\a"
 print -Pn "\e]1;`hostname | cut -d. -f1`\a"
 
 
-PROMPT='%{$fg[cyan]%}[%n@%m] %{$fg[yellow]%}%3~ %{$fg[magenta]%}→ %{$reset_color%}'
-RPROMPT='$(vi_mode_prompt_info) $(git_prompt_info) %{$reset_color%}%T %{$fg[white]%}%h%{$reset_color%}'
-
-MODE_INDICATOR="%{$fg[green]%}vi-mode%{$reset_color%}"
-
-ZSH_THEME_GIT_PROMPT_PREFIX="[git:"
-ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}"
-ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%}"
-ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}"
+PROMPT='
+%{$fg[cyan]%}[%m]  %{$fg[yellow]%}%3~  $(git_prompt_info) 
+%{$fg[magenta]%}%n %{$fg[magenta]%}→ %{$reset_color%}'
 
 
+RPROMPT='$(vi_mode_prompt_info) %{$reset_color%}%T %{$fg[white]%}%h%{$reset_color%}'
 
 
-ZSH_THEME_GIT_PROMPT_ADDED="%{$FG[082]%}+%{$reset_color%}"
-ZSH_THEME_GIT_PROMPT_MODIFIED="%{$FG[160]%}+%{$reset_color%}"
-ZSH_THEME_GIT_PROMPT_DELETED="%{$FG[160]%}x%{$reset_color%}"
-ZSH_THEME_GIT_PROMPT_RENAMED="%{$FG[220]%}>%{$reset_color%}"
-ZSH_THEME_GIT_PROMPT_UNMERGED="%{$FG[082]%}u%{$reset_color%}"
-ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$FG[160]%}?%{$reset_color%}"
+MODE_INDICATOR="%{$fg[green]%}vi-mode%{$reset_color%}"

+ 27 - 0
zsh/oh-my-zsh-custom/plugins/vi-mode/vi-mode.plugin.zsh

@@ -0,0 +1,27 @@
+#
+# This plugin is modified to work better with multiline prompts. The problem
+# and solutions are described in
+# https://github.com/robbyrussell/oh-my-zsh/pull/597
+# (basically, zle-line-init is taken out)
+#
+function zle-keymap-select {
+  zle reset-prompt
+}
+
+zle -N zle-keymap-select
+
+bindkey -v
+
+# if mode indicator wasn't setup by theme, define default
+if [[ "$MODE_INDICATOR" == "" ]]; then
+  MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}"
+fi
+
+function vi_mode_prompt_info() {
+  echo "${${KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/}"
+}
+
+# define right prompt, if it wasn't defined by a theme
+if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then
+  RPS1='$(vi_mode_prompt_info)'
+fi

+ 2 - 0
zsh/zshrc

@@ -40,6 +40,8 @@ source $ZSH/oh-my-zsh.sh
 alias h='history'
 alias h='history'
 ## don't show expansions, just execute, e.g. for !! and !$
 ## don't show expansions, just execute, e.g. for !! and !$
 setopt nohistverify
 setopt nohistverify
+## don't have the same history across tabs/windows
+setopt nosharehistory
 
 
 ## common typos
 ## common typos
 alias vf='cd'
 alias vf='cd'