diff --git a/.gitignore b/.gitignore index 3af6a41..ac982b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ aliases/local *.zwc +.zcompdump diff --git a/.zlogin b/.zlogin new file mode 120000 index 0000000..cfeb5da --- /dev/null +++ b/.zlogin @@ -0,0 +1 @@ +zlogin \ No newline at end of file diff --git a/.zprofile b/.zprofile new file mode 120000 index 0000000..018fc86 --- /dev/null +++ b/.zprofile @@ -0,0 +1 @@ +zprofile \ No newline at end of file diff --git a/.zshrc b/.zshrc new file mode 120000 index 0000000..c8b42f4 --- /dev/null +++ b/.zshrc @@ -0,0 +1 @@ +zshrc \ No newline at end of file diff --git a/env_template b/env_template new file mode 100644 index 0000000..de3fcee --- /dev/null +++ b/env_template @@ -0,0 +1,21 @@ +export ZDOTDIR="$HOME/.zsh" +PROMPT_UNICODE=yes +LANG=en_US.UTF-8 +export LANG +zcpath="$ZDOTDIR" + +# on foreign server I don't want to accidentaly alarm admins +sudo() { + echo "no root here"; +} + +su() { + echo "no root here"; +} + +# set modules to load. here: exclude highlight, because it is no fun over slow +# connections +ZMODLOAD_ONLY=( autoloader bindings completion vcs prompt ) + +source $zcpath/zprofile +source $zcpath/zshrc diff --git a/modules/autoloader/init b/modules/autoloader/init index 4e106ba..0ca7128 100644 --- a/modules/autoloader/init +++ b/modules/autoloader/init @@ -7,14 +7,13 @@ # Lets you load custom functions and zle widgets split into single files. # # zle widgets are stored in the "widgets" folder in your configuration directory -# (default: /etc/zsh, if you want to use this in a user configuration file, set -# the variable $zcpath to your zsh configuration directory) +# (set with $ZDOTDIR, see manpage. defaults to /etc/zsh) # # functions are stored in the "functions" folder analogous. # -ZWIDGETPATH=${ZWIDGETPATH:-"${zcpath:-/etc/zsh}/widgets"} -ZFUNCTIONPATH=${ZFUNCTIONPATH:-"${zcpath:-/etc/zsh}/functions"} +ZWIDGETPATH=${ZWIDGETPATH:-"${ZDOTDIR:-/etc/zsh}/widgets"} +ZFUNCTIONPATH=${ZFUNCTIONPATH:-"${ZDOTDIR:-/etc/zsh}/functions"} fpath+=( "${ZWIDGETPATH}" ) fpath+=( "${ZFUNCTIONPATH}" ) diff --git a/modules/loader.zsh b/modules/loader.zsh index cc52e36..6bed824 100644 --- a/modules/loader.zsh +++ b/modules/loader.zsh @@ -7,7 +7,7 @@ # # Modules are stored in the "modules" folder in your configuration directory # (default: /etc/zsh, if you want to use this in a user configuration file, set -# the variable $zcpath to your zsh configuration directory) +# the variable $ZDOTDIR to your zsh configuration directory in ~/.zshenv) # # Each module should have a file called "init". This file is sourced, when the # module is loaded and is responsible for sourcing any other files needed by the @@ -21,7 +21,7 @@ ################################# # Path to module directory -ZMODPATH=${ZMODPATH:-"${zcpath:-/etc/zsh}/modules"} +ZMODPATH=${ZMODPATH:-"${ZDOTDIR:-/etc/zsh}/modules"} . $ZMODPATH/helpers.zsh errdetails="" @@ -100,7 +100,8 @@ mod_check_dep() { if ! mod_queue "$dep" is_dep ${modpath}; then errdetails="$dep" return 1; - fi;; + fi + ;; "after") if [ -z "$ZMODLOAD_ONLY" ] \ || in_array "$dep" "${(@)ZMODLOAD_ONLY}"; then diff --git a/modules/prompt/init b/modules/prompt/init index bd804fc..77cefd7 100644 --- a/modules/prompt/init +++ b/modules/prompt/init @@ -61,8 +61,8 @@ function prompt_preexec { # if running gnu screen, set the window name to the last run command # FIXME any way to make this not change certain window titles (by window # number or if a title isn't already set?) - if [[ "$TERM" =~ "screen" ]] \ - && [[ "$(tmux show -w au)" != "automatic-rename off" ]]; then + if [[ -n "$TMUX" ]] \ + && ! tmux show -w | grep -q "automatic-rename off"; then local CMD=${1[(wr)^(*=*|ssh|sudo|-*)]} echo -ne "\ek$CMD\e\\" fi @@ -73,6 +73,8 @@ if mod_loaded todo; then count=$(todo_count all ${TO_READ_FILE:-$HOME/.to_read}) if [ "$count" -gt 1 ]; then echo -n "${PVPREFIX}${pathcolor}To read: $((count -1)) ${rpscolor}${PVSUFFIX}" + elif [ "$count" -lt 0 ]; then + echo -n "${PVPREFIX}${pathcolor}no todo${rpscolor}${PVSUFFIX}" fi } fi diff --git a/modules/todo/init b/modules/todo/init index 93bb543..ce50e80 100644 --- a/modules/todo/init +++ b/modules/todo/init @@ -1,10 +1,15 @@ #!/bin/zsh - -todo_count() { - if [ -n "$2" ]; then - file="--database $2" - else - file="-G" - fi - todo ${=file} -f +${1:-high} | wc -l -} +if command -v todo >/dev/null; then + todo_count() { + if [ -n "$2" ]; then + file="--database $2" + else + file="-G" + fi + todo ${=file} -f +${1:-high} | wc -l + } +else + todo_count() { + echo -1 + } +fi diff --git a/prompt b/prompt deleted file mode 100644 index ce69c59..0000000 --- a/prompt +++ /dev/null @@ -1,301 +0,0 @@ -#!/bin/zsh -# Best Goddamn zsh prompt in the whole world. -# Author: Seth House - -PROMPT_UNICODE=${PROMPT_UNICODE:-yes} -setopt prompt_subst - - -autoload -U colors && colors -autoload -U promptinit -autoload -Uz vcs_info - - -local reset -reset="%{${reset_color}%}" - -#=================================================================256-color-term -if [[ "`tput colors`" == "256" ]] || [[ "`tput colors`" == "88" ]] ; then - pathcolor="%{${FG[27]}%}" - ropathcolor="%{${FG[92]}%}" - - gitdirty="%{${FX[bold]}${FG[160]}%}" - gitstaged="%{${FX[bold]}${FG[34]}%}" - gitclean="%{${FG[240]}%}" - stycolor="%{${FG[240]}%}" - exitcolor=$gitdirty - rpscolor="%{${FG[238]}%}" - gituntracked="%{$FX[bold]$FG[253]%}●%{$reset$rpscolor%}" - - local ucnum - if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then - ucnum=196 - else - ucnum=47 - fi - if [ ! -z $SSH_CLIENT ]; then - ucnum=$((ucnum + 3)) - hostcolor="%{${FG[226]}%}" - else - hostcolor=$gitclean - fi - usercolor="%{${FX[bold]}${FG[$ucnum]}%}" -#===================================================================8-color-term -else - pathcolor="%{$fg_bold[blue]}%}" - - gitdirty="%{${fg[yellow]}%}" - gitstaged="%{${fg[green]}%}" - gitclean="%{$rightcolor%}" - vcs_revision="%{${fg[250]}%}" - - exitcolor="%{$gitdirty%}" - rpscolor="%{$fg_bold[black]}%}" - - if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then - if [ ! -z $SSH_CLIENT ]; then - usercolor="%{${fg_bold[yellow]}%}" - hostcolor="%{${fg_no_bold[blue]}%}" - else - usercolor="%{${fg_bold[red]}%}" - hostcolor="%{${fg_bold[black]}%}" - fi - else - if [ ! -z $SSH_CLIENT ]; then - usercolor="%{${fg_bold[blue]}%}" - hostcolor="%{${fg_no_bold[blue]}%}" - else - usercolor="%{${fg_bold[green]}%}" - hostcolor="%{${fg_bold[black]}%}" - fi - fi -fi - -if [[ "$PROMPT_UNICODE" = "yes" ]]; then - PVPREFIX="╼╢" - PVSUFFIX="╟╾" - PR_HBAR='─' - PR_VBAR='│' - CORNER_LU='╭' - CORNER_LD='╰' - CORNER_RU='╮' - CORNER_RD='╯' -else - PVPREFIX="[" - PVSUFFIX="]" - PR_HBAR='-' - PR_VBAR='|' -fi - -# Set up VCS_INFO -zstyle ':vcs_info:*' enable git hg svn -zstyle ':vcs_info:(hg*|git*):*' get-revision true -zstyle ':vcs_info:(hg*|git*):*' check-for-changes true - -zstyle ':vcs_info:hg*' formats "(%s)[%i%u %b %m]" # rev+changes branch misc -zstyle ':vcs_info:hg*' actionformats "(%s|${white}%a${rpscolor})[%i%u %b %m]" - -zstyle ':vcs_info:hg*:netbeans' use-simple true -zstyle ':vcs_info:hg*:*' get-bookmarks true -zstyle ':vcs_info:hg*:*' get-mq true - -zstyle ':vcs_info:hg*:*' get-unapplied true -zstyle ':vcs_info:hg*:*' patch-format "mq(%g):%n/%c %p" -zstyle ':vcs_info:hg*:*' nopatch-format "mq(%g):%n/%c %p" - -zstyle ':vcs_info:hg*:*' hgrevformat "%r" # only show local rev. -zstyle ':vcs_info:hg*:*' branchformat "%b" # only show branch -zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b$vcs_revision:%f%r%f" - -if [[ -z $(git ls-files --other --exclude-standard 2> /dev/null) ]] { - zstyle ':vcs_info:git*' formats "${GIT_PROMPT_PREFIX}(%s) %12.12i %c%u %b%m${GIT_PROMPT_SUFFIX}" # hash changes branch misc - zstyle ':vcs_info:git*' actionformats "(%s|${white}%a${rpscolor}) %12.12i %c%u %b%m" -} else { - zstyle ':vcs_info:git*' formats "${GIT_PROMPT_PREFIX}(%s) %12.12i %c%u${gituntracked} %b%m${GIT_PROMPT_SUFFIX}" # hash changes branch misc - zstyle ':vcs_info:git*' actionformats "(%s|${white}%a${rpscolor}) %12.12i %c%u %b%m" -} - - - - -zstyle ':vcs_info:*' stagedstr "$gitstaged●$rpscolor" -zstyle ':vcs_info:*' unstagedstr "$gitdirty●$rpscolor" - -# zstyle ':vcs_info:hg:*:-all-' command fakehg -# zstyle ':vcs_info:*+*:*' debug true - -zstyle ':vcs_info:hg*+set-hgrev-format:*' hooks hg-hashfallback -zstyle ':vcs_info:hg*+set-message:*' hooks mq-vcs -zstyle ':vcs_info:git*+set-message:*' hooks git-st git-stash - -function prompt_char { - git branch >/dev/null 2>/dev/null && echo '±' && return - hg root >/dev/null 2>/dev/null && echo '☿' && return - svn info >/dev/null 2>/dev/null && echo '☣' && return - echo '%#' -} - -exitstatus () { - local exitstatus=$? - - if [ $exitstatus -ne 0 ] ; then - if [ $exitstatus -gt 128 -a $exitstatus -lt 163 ] ; then - echo "${SIG_PROMPT_PREFIX}SIG$signals[$exitstatus-127]${SIG_PROMPT_SUFFIX}" - else - echo "${SIG_PROMPT_PREFIX}${exitstatus}${SIG_PROMPT_SUFFIX}" - fi - fi -} - - -### Dynamically set hgrevformat based on if the local rev is available -# We don't always know the local revision, e.g. if use-simple is set -# Truncate long hash to 12-chars but also allow for multiple parents -function +vi-hg-hashfallback() { - if [[ -z ${hook_com[localrev]} ]] ; then - local -a parents - - parents=( ${(s:+:)hook_com[hash]} ) - parents=( ${(@r:12:)parents} ) - hook_com[rev-replace]="${(j:+:)parents}" - - ret=1 - fi -} - -# Show remote ref name and number of commits ahead-of or behind -function +vi-git-st() { - local ahead behind remote - local -a gitstatus - - # Are we on a remote-tracking branch? - remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \ - --symbolic-full-name --abbrev-ref 2>/dev/null)} - - if [[ -n ${remote} ]] ; then - # for git prior to 1.7 - # ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l) - ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l) - (( $ahead )) && gitstatus+=( "${gitstaged}+${ahead}${rpscolor}" ) - - # for git prior to 1.7 - # behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l) - behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l) - (( $behind )) && gitstatus+=( "${gitdirty}-${behind}${rpscolor}" ) - - hook_com[branch]="${hook_com[branch]} [ ${remote}${gitstatus:+ }${gitstatus} ]" - fi -} - -# Show screen STY and tmux number -sty () { - local sty=$? - - if [ ! -z "$STY" ] || [ ! -z "$TMUX" ] ; then - echo "${SIG_PROMPT_PREFIX}${STY:+"SCREEN:"}${(S)STY/#*./}${STY+${TMUX+" - "}}${TMUX:+"TMUX:"}${TMUX/*,/}${SIG_PROMPT_SUFFIX}" - fi -} - -screennum() { - local att - local det - local dead - if [ -x /usr/bin/screen ]; then - att=`screen -ls | grep Attached | wc -l` - det=`screen -ls | grep Detached | wc -l` - dead=`screen -ls | grep Dead | wc -l` - echo "A:$att|D:$det|?:$dead" - fi -} - -# Show count of stashed changes -function +vi-git-stash() { - local -a stashes - - if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then - stashes=$(git stash list 2>/dev/null | wc -l) - hook_com[misc]+=" (${stashes} stashed)" - fi -} - -STYINFO=$(sty) -# Executed before each prompt -function precmd { - vcs_info - setprompt - RPS1='$usercolor◀%(?::$exitcolor${PVPREFIX})$(exitstatus)%(?::${PVSUFFIX})${stycolor}${PVPREFIX}$(sty)${rpscolor}${PVSUFFIX}${CORNER_RD}$reset' -} - - -# Executed after a command has been read and is to be executed. -function preexec { - # if running gnu screen, set the window name to the last run command - # FIXME any way to make this not change certain window titles (by window - # number or if a title isn't already set?) - if [[ "$TERM" =~ "screen" ]]; then - local CMD=${1[(wr)^(*=*|ssh|sudo|-*)]} - echo -ne "\ek$CMD\e\\" - fi -} - -function setprompt() { - local -a lines infoline - local x i filler i_width - - infoline+=( "${rpscolor}${CORNER_LU}" ) - - ### First, assemble the top line - # Current dir - [[ -w $PWD ]] && infoline+=( ${pathcolor} ) || infoline+=( ${ropathcolor} ) - infoline+=( "${PVPREFIX} %~ ${PVSUFFIX}${rpscolor}${PR_HBAR}" ) - - # Username & host - infoline+=( "${PVPREFIX} ${usercolor}%n${reset}@${hostcolor}%m${rpscolor} ${PVSUFFIX}" ) - - i_width=${(S)infoline//\%\{*\%\}} # search-and-replace color escapes - i_width=${#${(%)i_width}} # expand all escapes and count the chars - - if [[ "$PROMPT_UNICODE" = "yes" ]]; then - filler="${rpscolor}${(l:$(( $COLUMNS - $i_width - 1))::─:)}" - else - filler="${rpscolor}${(l:$(( $COLUMNS - $i_width - 1))::-:)}" - fi - infoline[3]=( "${infoline[3]}${PR_HBAR}${filler}${PR_HBAR}" ) - infoline+=( "${rpscolor}${CORNER_RU}" ) - - ### Now, assemble all prompt lines - lines+=( ${(j::)infoline} ) - scmline="${rpscolor}${PR_VBAR} ${vcs_info_msg_0_}${reset}" - i_width=${(S)scmline//\%\{*\%\}} # search-and-replace color escapes - i_width=${#${(%)i_width}} # expand all escapes and count the chars - filler="${rpscolor}${(l:$(( $COLUMNS - $i_width - 2)):: :)}${reset}" - - [[ -n ${vcs_info_msg_0_} ]] && lines+=( "${scmline}${filler}${rpscolor}${PR_VBAR}" ) - lines+=( "${CORNER_LD}${PVPREFIX} %(1j.${rpscolor}%j${reset} .)${usercolor}%%${reset} " ) - - ### Finally, set the prompt - PROMPT=${(F)lines} -} - -venv_rprompt () { - if [[ -n $VIRTUAL_ENV ]]; then - RPROMPT="${rpscolor} venv:$(basename $VIRTUAL_ENV)${reset}" - else - RPROMPT="" - fi -} - -# function zle-keymap-select { - # VIMODE="${${KEYMAP/vicmd/ M:command}/(main|viins)/}" - # zle reset-prompt -# } -# zle -N zle-keymap-select -# -########## Or this one?: -# function zle-line-init zle-keymap-select { - # RPS1="${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --}" - # RPS2=$RPS1 - # zle reset-prompt -# } -# zle -N zle-line-init -# zle -N zle-keymap-select diff --git a/zlogin b/zlogin index 9dd2c4b..4174c6a 100644 --- a/zlogin +++ b/zlogin @@ -1,3 +1,3 @@ #fortune -c -s #pal -r 7 -todo +command -v todo >/dev/null && todo diff --git a/zprofile b/zprofile index d6d1689..1a136ae 100644 --- a/zprofile +++ b/zprofile @@ -1,14 +1,12 @@ -# /etc/zsh/zprofile -# $Header: /var/cvsroot/gentoo-x86/app-shells/zsh/files/zprofile-1,v 1.1 2010/08/15 12:21:56 tove Exp $ - -# Load environment settings from profile.env, which is created by -# env-update from the files in /etc/env.d +# gentoo specific if [ -e /etc/profile.env ] ; then . /etc/profile.env fi -# You should override these in your ~/.zprofile (or equivalent) for per-user -# settings. For system defaults, you can add a new file in /etc/profile.d/. +if [ -e "$HOME/.profile" ]; then + . "$HOME/.profile" +fi + export EDITOR=${EDITOR:-/usr/bin/vim} export PAGER=${PAGER:-/usr/bin/less} export XDG_CONFIG_HOME="$HOME/.config" @@ -16,28 +14,21 @@ export XDG_CONFIG_HOME="$HOME/.config" # 077 would be more secure, but 022 is generally quite realistic umask 022 -# Set up PATH depending on whether we're root or a normal user. -# There's no real reason to exclude sbin paths from the normal user, -# but it can make tab-completion easier when they aren't in the -# user's PATH to pollute the executable namespace. -# -# It is intentional in the following line to use || instead of -o. -# This way the evaluation can be short-circuited and calling whoami is -# avoided. -#if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then - PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${ROOTPATH}:$PATH" -#else -# PATH="$HOME/.bin:/usr/local/bin:/usr/bin:/bin:${PATH}" -#fi +PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${ROOTPATH}:$PATH" + PATH="/usr/lib/colorgcc/bin/:${PATH}" + export PATH unset ROOTPATH shopts=$- setopt nullglob + +#more gentoo specific stuff for sh in /etc/profile.d/*.sh ; do [ -r "$sh" ] && . "$sh" done + unsetopt nullglob set -$shopts unset sh shopts diff --git a/zshrc b/zshrc index 1269691..565dfec 100644 --- a/zshrc +++ b/zshrc @@ -12,8 +12,8 @@ setopt short_loops setopt cdable_vars # autoload completions -fpath+=( "${zcpath:-/etc/zsh}/compdef" ) -autoload -U ${zcpath:-/etc/zsh}/compdef/*(:t) +fpath+=( "${ZDOTDIR:-/etc/zsh}/compdef" ) +autoload -U ${ZDOTDIR:-/etc/zsh}/compdef/*(:t) bindkey -v @@ -22,13 +22,13 @@ autoload -Uz zmv zmodload zsh/zftp -for i in ${zcpath:-/etc/zsh}/aliases/*~${zcpath:-/etc/zsh}/aliases/*.zwc; do +for i in ${ZDOTDIR:-/etc/zsh}/aliases/*~${ZDOTDIR:-/etc/zsh}/aliases/*.zwc; do . $i done stty -ixon -. ${zcpath:-/etc/zsh}/modules/loader.zsh && mod_init +. ${ZDOTDIR:-/etc/zsh}/modules/loader.zsh && mod_init echo $PATH | grep -q 'local' || . /etc/zsh/zprofile echo $PATH | grep -q 'sbin' || . /etc/zsh/zprofile