From e808d77ed363e89fbf07e57e8cfd8608b5bfa2ef Mon Sep 17 00:00:00 2001 From: Amand Tihon Date: Tue, 2 Jun 2009 10:54:15 +0200 Subject: [PATCH] Initial commit --- S10_zshopts | 25 ++++++++++++++++ S20_env | 16 +++++++++++ S21_path | 16 +++++++++++ S40_completion | 13 +++++++++ S50_aliases | 70 +++++++++++++++++++++++++++++++++++++++++++++ S60_git | 49 +++++++++++++++++++++++++++++++ S61_konsoletabs | 44 ++++++++++++++++++++++++++++ S90_prompt | 37 ++++++++++++++++++++++++ scripts/konsolewrap | 9 ++++++ scripts/telnetwrap | 11 +++++++ 10 files changed, 290 insertions(+) create mode 100644 S10_zshopts create mode 100644 S20_env create mode 100644 S21_path create mode 100644 S40_completion create mode 100644 S50_aliases create mode 100644 S60_git create mode 100644 S61_konsoletabs create mode 100644 S90_prompt create mode 100755 scripts/konsolewrap create mode 100755 scripts/telnetwrap diff --git a/S10_zshopts b/S10_zshopts new file mode 100644 index 0000000..d90bec0 --- /dev/null +++ b/S10_zshopts @@ -0,0 +1,25 @@ +#! /usr/bin/zsh + +if test -x =dircolors; then + eval "`dircolors`" + export ZLS_COLORS=$LS_COLORS +fi + +setopt auto_cd +setopt nobeep + +typeset -ga preexec_functions +typeset -ga precmd_functions +typeset -ga chpwd_functions + +[ -w $zsh_cache ] && HISTFILE=$zsh_cache/history + +HISTSIZE=10000 # size of history +LISTMAX=1000 # never ask +NULLCMD='cat' # use cat for > null commands +REPORTTIME=2 # report time if execution exceeds amount of seconds +SAVEHIST=10000 # maximum of history events to be save +LOGCHECK=60 +watch=(notme) # watch login/logout +WORDCHARS="*?_-.[]~/&;!#$%^(){}<>" + # part of word in line editor diff --git a/S20_env b/S20_env new file mode 100644 index 0000000..410fa0b --- /dev/null +++ b/S20_env @@ -0,0 +1,16 @@ +#! /usr/bin/zsh + +if [ x"$HOME" = x ] ; then + export HOME=$(cd ~ ; pwd) +fi + +if [ x"$HOSTNAME" = x ] ; then + export HOSTNAME=$(hostname) +fi + +export EMAIL="amand.tihon@iba-group.com" +export FULLNAME="Amand Tihon" + +export EDITOR=vim + + diff --git a/S21_path b/S21_path new file mode 100644 index 0000000..329e172 --- /dev/null +++ b/S21_path @@ -0,0 +1,16 @@ + +# Just make sure there are no duplicate in the PATH + +MY_PATH=(${(s.:.)PATH}) +typeset -U MY_PATH +MY_PATH=( + $HOME/bin + $MY_PATH + /{usr/,}sbin + ) + +export PATH=${(j.:.)MY_PATH} + + +fpath=(~/.zsh/functions $fpath) +export fpath diff --git a/S40_completion b/S40_completion new file mode 100644 index 0000000..9e51c62 --- /dev/null +++ b/S40_completion @@ -0,0 +1,13 @@ +#! /usr/bin/zsh + +hosts=($( ( \ + ( [ -r ~/.ssh/config ] && awk '/^host +[a-z]/ { print $2 }' ~/.ssh/config) ; \ + ( [ -r ~/.ssh/known_hosts ] && awk '{print $1}' ~/.ssh/known_hosts | tr , '\n') \ +) | sort -u)) + +zstyle ':completion:*:hosts' hosts $hosts +zstyle ':completion:*:hosts' list-colors '=(#b)(*)(.lln.iba)=01;30=01;31' '=[^.]#=01;31' + +users=(atihon ccadmin tcsadmin tcs clinical root) +zstyle ':completion:*' users $users + diff --git a/S50_aliases b/S50_aliases new file mode 100644 index 0000000..28b43ae --- /dev/null +++ b/S50_aliases @@ -0,0 +1,70 @@ +#! /usr/bin/zsh + +# ls en couleur : + +alias ls="ls --color=auto" +alias l="ls" +alias ll="ls -l" +alias lla="ls -al" +alias .="source" + +if [ -f /etc/debian_version ] +then + # Aliases pour apt : + alias search="apt-cache search" + alias show="apt-cache show" + alias policy="apt-cache policy" + + alias update="sudo apt-get update" + alias install="sudo apt-get install" + alias upgrade="sudo apt-get upgrade" + alias dist-upgrade="sudo apt-get dist-upgrade" + alias remove="sudo apt-get remove" +fi + +if [ -f /etc/SuSE-release ] +then + if [ -x /usr/bin/smart ] + then + # aliases for smart, if it's present + alias search="smart search" + alias show="smart info" + alias update="sudo smart update" + alias install="sudo smart install" + alias remove="sudo smart remove" + alias upgrade="sudo smart upgrade" + else + # Aliases for zypper + alias search="zypper search -d" + alias show="zypper info" + alias update="sudo zypper refresh" + alias install="sudo zypper install" + alias remove="sudo zypper remove" + + alias upgrade="sudo zypper update" + fi +fi + +# to avoid the cd in mc history : +setopt histignorespace +alias cd=' builtin cd' + +alias scr='screen -rd' + +# Konsole tab renaming. Courtesy of Sebastian Kuegler +# http://vizzzion.org/?blogentry=737 +if [ "$KONSOLE_DCOP_SESSION" ] +then + if [ `/usr/bin/whoami` != 'root' ] + then + alias ssh='~/.zsh.d/scripts/konsolewrap ssh' + alias lftp='~/.zsh.d/scripts/konsolewrap lftp' + alias sftp='~/.zsh.d/scripts/konsolewrap sftp' + alias su='~/.zsh.d/scripts/konsolewrap su' + alias telnet='~/.zsh.d/scripts/konsolewrap telnet' + alias rlogin='~/.zsh.d/scripts/konsolewrap rlogin' + alias rsh='~/.zsh.d/scripts/konsolwrap rsh' + + fi +fi + diff --git a/S60_git b/S60_git new file mode 100644 index 0000000..433cea7 --- /dev/null +++ b/S60_git @@ -0,0 +1,49 @@ +#! /usr/bin/zsh + +git_parse() { + + psvar=() + + local git_dir ref base_dir sub_dir action branch + git_dir=$(git rev-parse --git-dir 2> /dev/null) || return + + base_dir=${$(readlink -f "$git_dir/..")/$HOME/'~'} + + sub_dir=$(git rev-parse --show-prefix) + sub_dir=${sub_dir%/} + ref=$(git symbolic-ref HEAD 2> /dev/null) || return + + psvar[3]="" + + if [ -d "$git_dir/../.dotest" ]; then + if [ -f "$git_dir/../.dotest/rebasing" ]; then + psvar[3]="-rebase" + elif [ -f "$git_dir/../.dotest/applying" ]; then + psvar[3]="-am" + else + psvar[3]="-am-rebase" + fi + branch="$ref" + elif [ -f "$git_dir/.dotest-merge/interactive" ]; then + psvar[3]="-rebase-i" + branch="$(cat "$git_dir/.dotest-merge/head-name")" + elif [ -d "$git_dir/.dotest-merge" ]; then + psvar[3]="-rebase-m" + branch="$(cat "$git_dir/.dotest-merge/head-name")" + elif [ -f "$git_dir/MERGE_HEAD" ]; then + psvar[3]="-merge" + branch="$ref" + else + test -f "$git_dir/BISECT_LOG" && psvar[3]="bisect" + branch="$(git symbolic-ref HEAD 2>/dev/null)" || \ + branch="$(git describe --exact-match HEAD 2>/dev/null)" || \ + branch="$(cut -c1-7 "$git_dir/HEAD")..." + fi + + # Got here, we're in git + psvar[4]=${branch#refs/heads/} + psvar[5]=${base_dir} + psvar[6]=${sub_dir} +} + +precmd_functions+='git_parse' diff --git a/S61_konsoletabs b/S61_konsoletabs new file mode 100644 index 0000000..7488e06 --- /dev/null +++ b/S61_konsoletabs @@ -0,0 +1,44 @@ +#! /usr/binn/zsh + +# Change konsole tab to current path +konsole-rename-path () { + if [ "$KONSOLE_DCOP_SESSION" ] + then + local DIR + DIR=${PWD/#${HOME}/\~} + dcop ${KONSOLE_DCOP_SESSION} renameSession "$DIR" + fi +} + +# Change konsole tab to current command +konsole-rename-cmd () { + if [ "$KONSOLE_DCOP_SESSION" ] + then + # We don't need to change tab to "cd xyz" or precmd redefinition + # Yes, this is a dirty hack + if [[ "$1" != \ cd\ \"* && "$1" != \ precmd* ]] + then + local TXT + TXT="${1[0,33]}" + if [[ "$1" != "$TXT" ]] + then + TXT="${1[0,30]}..." + else + TXT="$1" + fi + dcop ${KONSOLE_DCOP_SESSION} renameSession "$TXT" + fi + fi +} + +precmd_functions+='konsole-rename-path' +preexec_functions+='konsole-rename-cmd' + +# On changing directory, when in mc (automatically called). +mc_chpwd () { + if [ -n "$MC_SID" ] + then + konsole-rename-path + fi +} + diff --git a/S90_prompt b/S90_prompt new file mode 100644 index 0000000..adc68c2 --- /dev/null +++ b/S90_prompt @@ -0,0 +1,37 @@ +#! /usr/bin/zsh + +autoload -U colors +colors +setopt prompt_subst + +# +# Prepare colors, ignoring length +# +C_NO="%{$reset_color%}" +C_BYELLOW="%{${fg_bold[yellow]}%}" +C_BRED="%{${fg_bold[red]}%}" +C_BCYAN="%{${fg_bold[cyan]}%}" +C_GREEN="%{${fg[green]}%}" +C_MAGENTA="%{${fg_bold[magenta]}%}" + + + +# +# Prompt parts +# +_username="${C_BYELLOW}%n${C_NO}" +_machine="${C_BRED}%m${C_NO}" +_hour="${C_BCYAN}[%D{%H:%M}]${C_NO}" + +_exitcode="%(?::${C_BRED}[ %? ]${C_NO} +)$(true)" + +_action="%(3v,%3v%,)" +_path='${C_GREEN}%(5v,%15<..<%5v%<<${C_NO}${C_MAGENTA}@%4v%3v${C_NO}${C_GREEN}/%15<..<%6v%<<,%25<..<%~%<<)${C_NO}' + + +# +# Now, the prompt itself +# +PROMPT="${_exitcode}${_hour} ${_username}@${_machine}:${_vcs}${_path}$ " + diff --git a/scripts/konsolewrap b/scripts/konsolewrap new file mode 100755 index 0000000..c64ba60 --- /dev/null +++ b/scripts/konsolewrap @@ -0,0 +1,9 @@ +#! /usr/bin/zsh +# This small script renames the konsole tab to the commands' last argument + +typeset -a args +args=$@ +lastarg="${args[(w)-1]}" +dcop ${KONSOLE_DCOP_SESSION} renameSession "$lastarg" +exec $cmd "$@" + diff --git a/scripts/telnetwrap b/scripts/telnetwrap new file mode 100755 index 0000000..a2241ae --- /dev/null +++ b/scripts/telnetwrap @@ -0,0 +1,11 @@ +#! /usr/bin/zsh +# This small script renames the konsole tab to the commands' last argument + +typeset -a args +args=$@ +lastarg="${args[(w)-1]}" +dcop ${KONSOLE_DCOP_SESSION} renameSession "$lastarg" +exec $cmd "$@" + + + -- 2.39.2