summaryrefslogtreecommitdiffstats
path: root/zshrc
diff options
context:
space:
mode:
Diffstat (limited to 'zshrc')
-rw-r--r--zshrc87
1 files changed, 87 insertions, 0 deletions
diff --git a/zshrc b/zshrc
new file mode 100644
index 0000000..96fbb32
--- /dev/null
+++ b/zshrc
@@ -0,0 +1,87 @@
+# Install oh-my-zsh-git (AUR)
+ZSH='/usr/share/oh-my-zsh/'
+
+setopt hist_ignore_all_dups
+setopt hist_find_no_dups
+
+CASE_SENSITIVE="true"
+COMPLETION_WAITING_DOTS="true"
+
+plugins=(
+ # auto complete with sudo
+ sudo
+ # better man pages with colors
+ colored-man-pages
+ # auto complete with git
+ git
+ # managing history
+ per-directory-history
+ history-substring-search
+)
+
+source "${ZSH}/oh-my-zsh.sh"
+
+# configure ↑ and ↓ to search zsh history
+bindkey '^[[A' history-substring-search-up
+bindkey '^[[B' history-substring-search-down
+
+# This will prompt the return code of the last command iff it is not 0
+# (ie. something went wrong with the last command).
+function precmd {
+ local last_ret="$?"
+
+ if [[ ${last_ret} -ne 0 ]]; then
+ echo "\033[0;33m→ ${last_ret}"
+ fi
+}
+
+# This will echo the right prompt format string.
+#
+# If the current directory is inside a git repository, it will print the root
+# folder name, followed by the relative path within the repository, followed by
+# the branch name.
+#
+# Otherwise, it just output the current directory.
+function get_rprompt {
+ if [[ -n $(current_branch) ]]; then
+ echo -n "%{%12F%}$(basename `git rev-parse --show-toplevel`):%{%f%}"
+ echo -n "%{%11F%}/$(git rev-parse --show-prefix | sed 's:/*$::')%{%f%}"
+ if [[ $(git status | grep "nothing to commit") ]]; then
+ echo -n " %{%2F%}($(current_branch))%{%f%}"
+ else
+ echo -n " %{%1F%}($(current_branch))%{%f%}"
+ fi
+ else
+ echo -n "%{%12F%}$(pwd)%{%f%}"
+ fi
+}
+
+PROMPT='%{%12F%}λ %{%f%}'
+RPROMPT='$(get_rprompt)'
+
+# Start SSH agent in order to type passphrases only once
+SSH_ENV="$HOME/.ssh/environment"
+
+function start_agent {
+ echo -n "Initialising new SSH agent... "
+ /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
+ echo succeeded
+ chmod 600 "${SSH_ENV}"
+ . "${SSH_ENV}" > /dev/null
+ for key in $(grep "IdentityFile" ~/.ssh/config | sed -e 's/\s*IdentityFile\s*//'); do
+ # eval echo is required to deal with the fact that keys pathes contains
+ # ~ and zsh won't expand them in a string “just like that”
+ ssh-add $(eval echo ${key})
+ done
+ ssh-add
+}
+
+# Source SSH settings, if applicable
+if [ -f "${SSH_ENV}" ]; then
+ . "${SSH_ENV}" > /dev/null
+ ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
+ start_agent;
+ }
+else
+ start_agent;
+fi