From 28d64103b9ebd7f855096dfbb03c6d34e470acda Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Wed, 10 Apr 2013 03:29:31 +0200 Subject: [PATCH 01/16] shell/aliases: Add aliases lt (ls -lt) and lat (ls -alt). --- shell/aliases.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/shell/aliases.in b/shell/aliases.in index 8bf77c4..34a51b6 100644 --- a/shell/aliases.in +++ b/shell/aliases.in @@ -56,13 +56,17 @@ ls() { LS_ENV LS_PATH LS_COLOR -C -F "$@" 2>&1 | less } -unalias ll la lal 2> /dev/null +unalias ll lt la lal lat 2> /dev/null # List the files in list format with access rights, etc. alias ll='ls -l' +# List the files sorted by last modification date. +alias lt='ls -l -t' # List all files. alias la='ls -a' # List all files in list format with access rights, etc. alias lal='ls -al' +# List all files sorted by last modification date. +alias lat='ls -al -t' # Make going up directories simple. -- 2.44.2 From 4bcae02cfd13f42ff10cfef0f6400b98b73de336 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Wed, 10 Apr 2013 03:33:34 +0200 Subject: [PATCH 02/16] shell/dircolors: Color "NEWS" file. --- shell/dircolors.in | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/dircolors.in b/shell/dircolors.in index 35a7001..bba92e6 100644 --- a/shell/dircolors.in +++ b/shell/dircolors.in @@ -73,6 +73,7 @@ CHR 00 .README 35;01 .readme 35;01 # Misc files: bold magenta. +*NEWS 35;01 *TODO 35;01 *todo 35;01 -- 2.44.2 From 020f30113df431a611f9a6ec9d963f1da38bb8ec Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Wed, 10 Apr 2013 04:03:09 +0200 Subject: [PATCH 03/16] setup.sh: Create alias for tig (git tig) if it's not available. --- setup.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/setup.sh b/setup.sh index 1be636c..c5406e6 100755 --- a/setup.sh +++ b/setup.sh @@ -116,6 +116,11 @@ generate perl shell/aliases \ }' \ "$ls_env" "$ls_path" "$ls_color" "$column" +# If `tig` is not available use my simple replacement. +if ! installed tig; then + echo "alias tig='git tig'" >>shell/aliases +fi + # Check if grep supports --color=auto. if echo test | grep --color=auto test >/dev/null 2>&1; then : -- 2.44.2 From 975eb217f9e6396c725f2aa2ab6485b42166afbe Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 11 Apr 2013 14:43:27 +0200 Subject: [PATCH 04/16] sshd_config: Minor documentation fix. --- sshd_config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sshd_config b/sshd_config index 8c73565..4f54f5e 100644 --- a/sshd_config +++ b/sshd_config @@ -51,7 +51,7 @@ StrictModes yes # Allow more sessions per network connection (e.g. from ControlMaster/-M). # When not enough sessions are available this message is sent by ssh: # "mux_client_request_session: session request failed: Session open refused by -# peer". Not necessary on all servers, therefore deactivated here. +# peer". Not necessary on all servers. #MaxSessions 30 # Don't accept any environment variables from the client (default). @@ -63,7 +63,7 @@ PermitUserEnvironment no # Send a message after the given seconds of inactivity through the encrypted # channel. Used to detect stale connections more quickly. Not necessary on all -# servers, therefore deactivated here. +# servers. #ClientAliveInterval 60 # Disconnect the client if more than max count alive messages were lost # (default). With the setting above this detects a broken connection after 3 -- 2.44.2 From f202f2a1f6054126148f903325a36ed323c6f241 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 12 Apr 2013 00:30:16 +0200 Subject: [PATCH 05/16] zsh/rc: Consistently use [[ instead of [. --- zsh/rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh/rc b/zsh/rc index 5889186..9755527 100644 --- a/zsh/rc +++ b/zsh/rc @@ -878,7 +878,7 @@ periodic() { # Display fortunes. (( $+commands[fortune] )) && fortune -ac # Display reminders. - (( $+commands[rem] )) && [ -f ~/.reminders ] && rem -h + (( $+commands[rem] )) && [[ -f ~/.reminders ]] && rem -h } -- 2.44.2 From 75acbd549c35dc45c90894d22ccd7f0235d7f0ed Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Fri, 12 Apr 2013 15:54:09 +0200 Subject: [PATCH 06/16] crontab.d/jobs: Add support to run job every 6 hours. Also add crontab.d/jobs/jobs.hourly6/ directory. --- crontab.d/jobs | 3 ++- crontab.d/jobs.hourly6/.gitignore | 0 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 crontab.d/jobs.hourly6/.gitignore diff --git a/crontab.d/jobs b/crontab.d/jobs index de29c35..fb83d9a 100644 --- a/crontab.d/jobs +++ b/crontab.d/jobs @@ -30,5 +30,6 @@ PATH=$HOME/bin:$HOME/.shell/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/u 47 6 * * 7 run-parts --report .crontab.d/jobs.weekly 52 6 1 * * run-parts --report .crontab.d/jobs.monthly -# Run every 8 hours. +# Run every x hours. +31 */6 * * * run-parts --report .crontab.d/jobs.hourly6 39 */8 * * * run-parts --report .crontab.d/jobs.hourly8 diff --git a/crontab.d/jobs.hourly6/.gitignore b/crontab.d/jobs.hourly6/.gitignore new file mode 100644 index 0000000..e69de29 -- 2.44.2 From 21ad1999eaa420b2a03585b086effce0215a5ef4 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 11 Apr 2013 21:49:25 +0200 Subject: [PATCH 07/16] shell/env: Add missing timezone to comment. --- shell/env | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/env b/shell/env index 74f676c..f11e687 100644 --- a/shell/env +++ b/shell/env @@ -20,7 +20,8 @@ source_debug ". ~/.shell/env" # Use UTF-8 encoding in the terminal. Don't use LC_ALL as it's used for -# debugging purposes. Thanks to twb in Freenode/#screen (2009-10-02 10:25). +# debugging purposes. Thanks to twb in #screen on Freenode (2009-10-02 10:25 +# CET). LANG=en_US.UTF-8 export LANG -- 2.44.2 From 9d22fdb6ba21eb87266fac19f252e548dda78d7a Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 13 Apr 2013 03:45:13 +0200 Subject: [PATCH 08/16] setup.sh: Link ~/.ssh/config if ~/.ssh/ exists. --- setup.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index c5406e6..7bf7882 100755 --- a/setup.sh +++ b/setup.sh @@ -266,4 +266,6 @@ if installed htop; then mkdir -p ~/.config/htop link htoprc ~/.config/htop/htoprc fi - +if test -d ~/.ssh; then + link ssh_config ~/.ssh/config +fi -- 2.44.2 From 6de4a52bedfdf81e90186d9c4e100b56815ddad5 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Tue, 16 Apr 2013 00:08:31 +0200 Subject: [PATCH 09/16] setup.sh: Only link ssh_config if ~/.ssh is owned by user. --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index 7bf7882..b1b14de 100755 --- a/setup.sh +++ b/setup.sh @@ -266,6 +266,6 @@ if installed htop; then mkdir -p ~/.config/htop link htoprc ~/.config/htop/htoprc fi -if test -d ~/.ssh; then +if test -d ~/.ssh && test -O ~/.ssh; then link ssh_config ~/.ssh/config fi -- 2.44.2 From 9579b63e1bac6747a8ff6dee8866fae5a90ee3a0 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Mon, 15 Apr 2013 21:11:49 +0200 Subject: [PATCH 10/16] ssh_config: Use GatewayPorts no. --- ssh_config | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ssh_config b/ssh_config index 31c8e6d..6a2d79a 100644 --- a/ssh_config +++ b/ssh_config @@ -48,6 +48,9 @@ Host * PasswordAuthentication yes PubkeyAuthentication yes +# Bind local forwardings to loopback only. This way no remote hosts can access +# them (default). + GatewayPorts no # Abort if not all requested port forwardings can be set up. ExitOnForwardFailure yes -- 2.44.2 From b35fec23cb20e28707660d8917fe37bd51b9811c Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Mon, 15 Apr 2013 21:55:50 +0200 Subject: [PATCH 11/16] zsh/rc: Documentation update. --- zsh/rc | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/zsh/rc b/zsh/rc index 9755527..be0b9a2 100644 --- a/zsh/rc +++ b/zsh/rc @@ -68,7 +68,8 @@ setopt correct # Enable zsh's extended glob abilities. setopt extendedglob -# Don't exit if is pressed. +# Don't exit if is pressed. Prevents exiting the shell by accident (e.g. +# pressing twice). setopt ignoreeof @@ -94,7 +95,7 @@ bindkey -a -r '^[OA' '^[OB' '^[OC' '^[OD' '^[[A' '^[[B' '^[[C' '^[[D' # Make sure every entry in $fpath is unique. typeset -U fpath # ~/.zsh/functions/completion is a symbolic link to the Completion directory -# of a Zsh CVS checkout. Use it to get the newest completions if available. +# of a Zsh Git checkout. Use it to get the newest completions if available. if [[ -d ~/.zsh/functions/completion ]]; then fpath=(~/.zsh/functions/completion/*/*(/) $fpath) fi @@ -346,7 +347,8 @@ precmd_functions+=(longrun_precmd) # if not 0. # # The prompt is in green and blue to make easily detectable, the error exit -# code in red and bold and the job count in yellow. +# code in red and bold and the job count in yellow. Designed for dark +# terminals. # # Thanks to Adam's prompt for the basic idea of this prompt. prompt_precmd() { @@ -382,9 +384,9 @@ prompt_precmd() { host="%U${host}%u" fi - # Number of background processes in yellow. + # Number of background processes in yellow if not zero. local background="%(1j.${yellow}%j${default}.)" - # Exit code in bright red if not zero. + # Exit code in bright red in parentheses if not zero. local exitcode="%(?..(${red}%B%?%b${default}%) )" # Prefix characters in first and second line. @@ -420,14 +422,14 @@ ${bottom_prefix}${user}@${host} ${background}%# ${exitcode}" precmd_functions+=(prompt_precmd) -# When screen, tmux, xterm or rxvt is used set the name of the window to the -# currently running program. +# When GNU screen, tmux, xterm or rxvt is used set the name of the window to +# the currently running program. # # When a program is started preexec() sets the window's name to it; when it # stops precmd() resets the window's name to 'zsh'. 'fg' is supported and sets # the window's name to the resumed job. # -# It works with screen, tmux, xterm and rxvt. +# It works with GNU screen, tmux, xterm and rxvt. # # If a command is run with sudo or if the shell is running as root then a ! is # added at the beginning of the command to make this clear. If a command is @@ -451,7 +453,7 @@ if [[ $TERM == screen* || $TERM == xterm* || $TERM == rxvt* ]]; then # Get the program name with its arguments. local program_name=$1 - # When sudo is used use real program name instead, but with an + # When sudo is used, use real program name instead, but with an # exclamation mark at the beginning (handled below). local program_sudo= if [[ $program_name == sudo* ]]; then @@ -541,8 +543,8 @@ if [[ $TERM == screen* || $TERM == xterm* || $TERM == rxvt* ]]; then window_reset= } - # Sets the window title. Works with screen, tmux (which uses screen as - # TERM), xterm and rxvt. (V) escapes all non-printable characters. Thanks + # Sets the window title. Works with GNU screen, tmux (which uses screen as + # TERM), xterm and rxvt. (V) escapes all non-printable characters, thanks # to Mikachu in #zsh on Freenode (2010-08-07 17:09 CEST). if [[ $TERM == screen* ]]; then window_title() { @@ -728,7 +730,7 @@ alias -g EN='2>/dev/null' alias -g L='2>&1 | less' alias -g LS='2>&1 | less -S' # -S prevents wrapping of long lines alias -g D='2>&1 | colordiff | less' -# Global aliases for often used commands in the command line. +# Global aliases for often used commands. alias -g A='| awk' alias -g G='| grep' alias -g H='| head' @@ -814,7 +816,7 @@ fi # LOAD ADDITIONAL CONFIGURATION FILES # Configuration option for rc.local to use GNU screen/tmux. By default GNU -# screen is used. Possible values: screen, tmux. +# screen is used. Possible values: screen, tmux and empty (no value). use_multiplexer=screen source_config ~/.zsh/rc.local @@ -866,13 +868,13 @@ fi # cases it doesn't work, the E alias can be used as workaround. # # Moved in the "run commands" section to prevent one unnecessary zsh process -# when starting screen/tmux (see above). +# when starting GNU screen/tmux (see above). exec 2>>(while read -r -k -u 0 line; do printf '\e[91m%s\e[0m' "$line"; print -n $'\0'; done &) -# Run the following programs every 4 hours. +# Run the following programs every 4 hours (and when zsh starts). PERIOD=14400 periodic() { # Display fortunes. -- 2.44.2 From 2c96f7708cecf5f7eebf8e3349eb8f2a8eee1694 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Mon, 15 Apr 2013 21:58:25 +0200 Subject: [PATCH 12/16] zsh/rc: Minor cleanup. --- zsh/rc | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/zsh/rc b/zsh/rc index be0b9a2..5cad9c8 100644 --- a/zsh/rc +++ b/zsh/rc @@ -16,7 +16,7 @@ # along with this file. If not, see . -source_debug ". ~/.zsh/rc" +source_debug '. ~/.zsh/rc' # HELPER FUNCTIONS @@ -806,10 +806,8 @@ fi if [[ $OSTYPE == linux* ]]; then # Settings when creating Debian packages. - DEBEMAIL=simon@ruderich.org - export DEBEMAIL - DEBFULLNAME='Simon Ruderich' - export DEBFULLNAME + export DEBEMAIL=simon@ruderich.org + export DEBFULLNAME='Simon Ruderich' fi @@ -838,9 +836,9 @@ if [[ $TERM != dumb && $TERM != linux && -z $STY && -z $TMUX ]]; then # As we exec later we have to set the title here. if [[ $use_multiplexer = screen ]]; then - window_preexec "screen" + window_preexec screen elif [[ $use_multiplexer = tmux ]]; then - window_preexec "tmux" + window_preexec tmux fi # Create a new session if none is running. @@ -870,8 +868,8 @@ fi # Moved in the "run commands" section to prevent one unnecessary zsh process # when starting GNU screen/tmux (see above). exec 2>>(while read -r -k -u 0 line; do - printf '\e[91m%s\e[0m' "$line"; - print -n $'\0'; + printf '\e[91m%s\e[0m' "$line" + print -n $'\0' done &) # Run the following programs every 4 hours (and when zsh starts). @@ -884,6 +882,6 @@ periodic() { } -source_debug ". ~/.zsh/rc (done)" +source_debug '. ~/.zsh/rc (done)' # vim: ft=zsh -- 2.44.2 From abffe4a5d42482508709c25797961e1760f3bcc3 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 27 Apr 2013 16:04:23 +0200 Subject: [PATCH 13/16] zsh/rc: Prefix all functions and global variables with zshrc_. --- zsh/rc | 114 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/zsh/rc b/zsh/rc index 5cad9c8..dea4804 100644 --- a/zsh/rc +++ b/zsh/rc @@ -24,7 +24,7 @@ source_debug '. ~/.zsh/rc' # Return the name of the program which is called in the foreground with `fg`. # $1 is the name of the program (optional). If it's not 'fg' or 'fg *' it's # returned unchanged. -resolve_fg_to_resumed_job_name() { +zshrc_resolve_fg_to_resumed_job_name() { # $REPLY is used by convention for scalars ($reply for arrays) to return # values from functions. unset it here to prevent problems when REPLY is # bound to an integer or similar. Thanks to Mikachu in #zsh on Freenode @@ -154,8 +154,8 @@ setopt histignorespace # returned. Very useful to get old commands quickly - in addition to the # history commands (!..). Thanks to Mikachu in #zsh on Freenode (2010-01-17 # 12:47 CET) for the information how to a use function with bindkey. -zle -N my-vi-history-beginning-search-backward -my-vi-history-beginning-search-backward() { +zle -N zshrc-vi-history-beginning-search-backward +zshrc-vi-history-beginning-search-backward() { local not_at_beginning_of_line if [[ $CURSOR -ne 0 ]]; then not_at_beginning_of_line=yes @@ -170,7 +170,7 @@ my-vi-history-beginning-search-backward() { zle vi-forward-char fi } -bindkey '^P' my-vi-history-beginning-search-backward +bindkey '^P' zshrc-vi-history-beginning-search-backward bindkey -a '^P' history-beginning-search-backward # binding for Vi-mode # Here only Vi-mode is necessary as ^P enters Vi-mode and ^N only makes sense # after calling ^P. @@ -250,7 +250,7 @@ if [[ $ZSH_VERSION == (4.3.<9->*|4.<4->*|<5->*) || # Default to run vcs_info. If possible we prevent running it later for # speed reasons. If set to a non empty value vcs_info is run. - FORCE_RUN_VCS_INFO=1 + zshrc_force_run_vcs_info=1 # Cache system inspired by Bart Trojanowski # (http://jukie.net/~bart/blog/pimping-out-zsh-prompt). @@ -262,8 +262,8 @@ if [[ $ZSH_VERSION == (4.3.<9->*|4.<4->*|<5->*) || # If the shell just started up or we changed directories (or for other # custom reasons) we must run vcs_info. - if [[ -n $FORCE_RUN_VCS_INFO ]]; then - FORCE_RUN_VCS_INFO= + if [[ -n $zshrc_force_run_vcs_info ]]; then + zshrc_force_run_vcs_info= return fi @@ -283,26 +283,26 @@ if [[ $ZSH_VERSION == (4.3.<9->*|4.<4->*|<5->*) || # Must run vcs_info when changing directories. prompt_chpwd() { - FORCE_RUN_VCS_INFO=1 + zshrc_force_run_vcs_info=1 } chpwd_functions+=(prompt_chpwd) # Used by prompt code below to determine if vcs_info should be run. - RUN_VCS_INFO=1 + zshrc_use_vcs_info=1 else - RUN_VCS_INFO= + zshrc_use_vcs_info= fi -typeset -a longrun_data -longrun_data=() +typeset -a zshrc_longrun_data +zshrc_longrun_data=() # Display runtime in seconds for long running programs (> 60 seconds) and send # a bell to notify me. -longrun_preexec() { +zshrc_longrun_preexec() { local program="$3" # Handle fg. local REPLY - resolve_fg_to_resumed_job_name "$program" + zshrc_resolve_fg_to_resumed_job_name "$program" program="$REPLY" # Don't track the time for certain (possible) long running processes which @@ -310,35 +310,35 @@ longrun_preexec() { for ignore in elinks man mutt vim; do case $program in $ignore | $ignore\ *) - longrun_data=() + zshrc_longrun_data=() return ;; esac done - longrun_data=("$program" $EPOCHSECONDS) + zshrc_longrun_data=("$program" $EPOCHSECONDS) } -longrun_precmd() { +zshrc_longrun_precmd() { # No previous timestamp available or disabled for this command, ignore. - if [[ -z $longrun_data ]]; then + if [[ -z $zshrc_longrun_data ]]; then return fi - local difference=$(( EPOCHSECONDS - longrun_data[2] )) + local difference=$(( EPOCHSECONDS - zshrc_longrun_data[2] )) if [[ $difference -gt 60 ]]; then echo echo -n "${fg[yellow]}" - echo -n "~> ${(V)longrun_data[1]} took $difference seconds." + echo -n "~> ${(V)zshrc_longrun_data[1]} took $difference seconds." echo -n "${fg[default]}" echo "\a" # send bell fi # Clear status. Prevents displaying old status information when pressing # enter with an empty command line. - longrun_data=() + zshrc_longrun_data=() } -preexec_functions+=(longrun_preexec) -precmd_functions+=(longrun_precmd) +preexec_functions+=(zshrc_longrun_preexec) +precmd_functions+=(zshrc_longrun_precmd) # Set the prompt. A two line prompt is used. On the top left the current # working directory is displayed, on the right vcs_info (if available) and the @@ -351,14 +351,14 @@ precmd_functions+=(longrun_precmd) # terminals. # # Thanks to Adam's prompt for the basic idea of this prompt. -prompt_precmd() { +zshrc_prompt_precmd() { # Regex to remove elements which take no space. Used to calculate the # width of the top prompt. Thanks to Bart's and Adam's prompt code in # Functions/Prompts/prompt_*_setup. local zero='%([BSUbfksu]|([FB]|){*})' # Call vcs_info before every prompt. - if [[ -n $RUN_VCS_INFO ]]; then + if [[ -n $zshrc_use_vcs_info ]]; then vcs_info else vcs_info_msg_0_= @@ -419,7 +419,7 @@ prompt_precmd() { PROMPT="${top_prefix}${top_left}${top_separator}${top_right} ${bottom_prefix}${user}@${host} ${background}%# ${exitcode}" } -precmd_functions+=(prompt_precmd) +precmd_functions+=(zshrc_prompt_precmd) # When GNU screen, tmux, xterm or rxvt is used set the name of the window to @@ -443,13 +443,13 @@ precmd_functions+=(prompt_precmd) if [[ $TERM == screen* || $TERM == xterm* || $TERM == rxvt* ]]; then # Is set to a non empty value to reset the window name in the next # precmd() call. - window_reset=yes + zshrc_window_reset=yes # Is set to a non empty value when the shell is running as root. if [[ $UID -eq 0 ]]; then - window_root=yes + zshrc_window_root=yes fi - window_preexec() { + zshrc_window_preexec() { # Get the program name with its arguments. local program_name=$1 @@ -463,7 +463,7 @@ if [[ $TERM == screen* || $TERM == xterm* || $TERM == rxvt* ]]; then # Handle fg. local REPLY - resolve_fg_to_resumed_job_name "$program_name" + zshrc_resolve_fg_to_resumed_job_name "$program_name" program_name="$REPLY" # Remove all arguments from the program name. @@ -492,7 +492,7 @@ if [[ $TERM == screen* || $TERM == xterm* || $TERM == rxvt* ]]; then # Add an exclamation mark at the beginning if running with sudo or if # running zsh as root. - if [[ -n $program_sudo || -n $window_root ]]; then + if [[ -n $program_sudo || -n $zshrc_window_root ]]; then program_name=!$program_name fi @@ -512,15 +512,15 @@ if [[ $TERM == screen* || $TERM == xterm* || $TERM == rxvt* ]]; then fi # Set the window name to the currently running program. - window_title "$program_name" + zshrc_window_title "$program_name" # Tell precmd() to reset the window name when the program stops. - window_reset=yes + zshrc_window_reset=yes } - window_precmd() { + zshrc_window_precmd() { # Abort if no window name reset is necessary. - [[ -z $window_reset ]] && return + [[ -z $zshrc_window_reset ]] && return # Reset the window name to 'zsh'. local name=zsh @@ -531,41 +531,41 @@ if [[ $TERM == screen* || $TERM == xterm* || $TERM == rxvt* ]]; then fi # Prepend prefixes like in window_preexec(). - if [[ -n $window_root ]]; then + if [[ -n $zshrc_window_root ]]; then name="!$name" fi if [[ -n $SSH_CONNECTION ]]; then name="@$name" fi - window_title $name + zshrc_window_title $name # Just reset the name, so no screen reset necessary for the moment. - window_reset= + zshrc_window_reset= } # Sets the window title. Works with GNU screen, tmux (which uses screen as # TERM), xterm and rxvt. (V) escapes all non-printable characters, thanks # to Mikachu in #zsh on Freenode (2010-08-07 17:09 CEST). if [[ $TERM == screen* ]]; then - window_title() { + zshrc_window_title() { print -n "\ek${(V)1}\e\\" } elif [[ $TERM == xterm* || $TERM == rxvt* ]]; then - window_title() { + zshrc_window_title() { print -n "\e]2;${(V)1}\e\\" } else # Fallback if another TERM is used. - window_title() { } + zshrc_window_title() { } fi # Add the preexec() and precmd() hooks. - preexec_functions+=(window_preexec) - precmd_functions+=(window_precmd) + preexec_functions+=(zshrc_window_preexec) + precmd_functions+=(zshrc_window_precmd) else # Fallback if another TERM is used, necessary to run screen (see below in # "RUN COMMANDS"). - window_preexec() { } + zshrc_window_preexec() { } fi @@ -749,8 +749,8 @@ alias -g .....='../../../..' # is empty. I open so much windows that I don't know in which I have something # important. This helps me to remember which windows are empty (I run clear # after I finished my work in a window). -if [[ -n $window_reset ]]; then - alias clear='clear; window_reset=yes; window_precmd reset' +if [[ -n $zshrc_window_reset ]]; then + alias clear='clear; zshrc_window_reset=yes; zshrc_window_precmd reset' fi @@ -815,7 +815,7 @@ fi # Configuration option for rc.local to use GNU screen/tmux. By default GNU # screen is used. Possible values: screen, tmux and empty (no value). -use_multiplexer=screen +zshrc_use_multiplexer=screen source_config ~/.zsh/rc.local @@ -827,32 +827,32 @@ source_config ~/.zsh/rc.local # through ssh. if [[ $TERM != dumb && $TERM != linux && -z $STY && -z $TMUX ]]; then # Get running detached sessions. - if [[ $use_multiplexer = screen ]]; then + if [[ $zshrc_use_multiplexer = screen ]]; then session=$(screen -list | grep 'Detached' | awk '{ print $1; exit }') - elif [[ $use_multiplexer = tmux ]]; then + elif [[ $zshrc_use_multiplexer = tmux ]]; then session=$(tmux list-sessions 2>/dev/null \ | sed '/(attached)$/ d; s/^\([0-9]\{1,\}\).*$/\1/; q') fi # As we exec later we have to set the title here. - if [[ $use_multiplexer = screen ]]; then - window_preexec screen - elif [[ $use_multiplexer = tmux ]]; then - window_preexec tmux + if [[ $zshrc_use_multiplexer = screen ]]; then + zshrc_window_preexec screen + elif [[ $zshrc_use_multiplexer = tmux ]]; then + zshrc_window_preexec tmux fi # Create a new session if none is running. if [[ -z $session ]]; then - if [[ $use_multiplexer = screen ]]; then + if [[ $zshrc_use_multiplexer = screen ]]; then exec screen - elif [[ $use_multiplexer = tmux ]]; then + elif [[ $zshrc_use_multiplexer = tmux ]]; then exec tmux fi # Reattach to a running session. else - if [[ $use_multiplexer = screen ]]; then + if [[ $zshrc_use_multiplexer = screen ]]; then exec screen -r $session - elif [[ $use_multiplexer = tmux ]]; then + elif [[ $zshrc_use_multiplexer = tmux ]]; then exec tmux attach-session -t $session fi fi -- 2.44.2 From c464b056d6900011fcb2a22c7bb8cf130b21b238 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 27 Apr 2013 16:14:35 +0200 Subject: [PATCH 14/16] zsh/rc: Remove unnecessary variable zshrc_window_root. --- zsh/rc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/zsh/rc b/zsh/rc index dea4804..7a7dbae 100644 --- a/zsh/rc +++ b/zsh/rc @@ -444,10 +444,6 @@ if [[ $TERM == screen* || $TERM == xterm* || $TERM == rxvt* ]]; then # Is set to a non empty value to reset the window name in the next # precmd() call. zshrc_window_reset=yes - # Is set to a non empty value when the shell is running as root. - if [[ $UID -eq 0 ]]; then - zshrc_window_root=yes - fi zshrc_window_preexec() { # Get the program name with its arguments. @@ -492,7 +488,7 @@ if [[ $TERM == screen* || $TERM == xterm* || $TERM == rxvt* ]]; then # Add an exclamation mark at the beginning if running with sudo or if # running zsh as root. - if [[ -n $program_sudo || -n $zshrc_window_root ]]; then + if [[ -n $program_sudo || $UID -eq 0 ]]; then program_name=!$program_name fi @@ -531,7 +527,7 @@ if [[ $TERM == screen* || $TERM == xterm* || $TERM == rxvt* ]]; then fi # Prepend prefixes like in window_preexec(). - if [[ -n $zshrc_window_root ]]; then + if [[ $UID -eq 0 ]]; then name="!$name" fi if [[ -n $SSH_CONNECTION ]]; then -- 2.44.2 From e696edbf63b5ba5727b8bd8037dfa690b298b6a2 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 27 Apr 2013 16:22:18 +0200 Subject: [PATCH 15/16] zsh/rc: Enable warn_create_global. --- zsh/rc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zsh/rc b/zsh/rc index 7a7dbae..2712314 100644 --- a/zsh/rc +++ b/zsh/rc @@ -19,6 +19,11 @@ source_debug '. ~/.zsh/rc' +# Warn when creating global variables from inside a function. Needs to be set +# before declaring a function. +setopt warn_create_global + + # HELPER FUNCTIONS # Return the name of the program which is called in the foreground with `fg`. -- 2.44.2 From b4b39d3d211c1cb299471d697b0d2701a4a0779c Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 27 Apr 2013 16:25:44 +0200 Subject: [PATCH 16/16] zsh/rc: Use ${..} for color variables. It's more readable. --- zsh/rc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zsh/rc b/zsh/rc index 2712314..734040f 100644 --- a/zsh/rc +++ b/zsh/rc @@ -234,16 +234,16 @@ if [[ $ZSH_VERSION == (4.3.<9->*|4.<4->*|<5->*) || if [[ $ZSH_VERSION == (4.3.<11->*|4.<4->*|<5->*) || -d ~/.zsh/functions/vcs_info ]]; then zstyle ':vcs_info:*' formats \ - "($green%b%u%c$default:$blue%s$default)" + "(${green}%b%u%c${default}:${blue}%s${default})" zstyle ':vcs_info:*' actionformats \ - "($green%b%u%c$default/$red%a$default:$blue%s$default)" + "(${green}%b%u%c${default}/${red}%a${default}:${blue}%s${default})" else # In older versions %u and %c are not defined yet and are not # correctly expanded. zstyle ':vcs_info:*' formats \ - "($green%b$default:$blue%s$default)" + "(${green}%b${default}:${blue}%s${default})" zstyle ':vcs_info:*' actionformats \ - "($green%b$default/$red%a$default:$blue%s$default)" + "(${green}%b${default}/${red}%a${default}:${blue}%s${default})" fi # Set style for formats/actionformats when unstaged (%u) and staged (%c) # changes are detected in the repository; check-for-changes must be set to -- 2.44.2