Last active
November 11, 2021 00:08
-
-
Save irl/5199154 to your computer and use it in GitHub Desktop.
My .zshrc file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
### Fix rxvt to work on machines that don't know about | |
### the 256color variant | |
if [ $TERM = "rxvt-unicode-256color" ]; then | |
export TERM="rxvt-unicode" | |
fi | |
### History settings | |
HISTFILE=~/.histfile | |
HISTSIZE=1000 | |
SAVEHIST=1000 | |
### Go to directories with explicit 'cd' | |
setopt autocd | |
### Use vim-style keys | |
bindkey -v | |
### Set up autocompletion | |
zstyle :compinstall filename '/meta/i/irl/.zshrc' | |
autoload -Uz compinit | |
compinit | |
### Set up default applications | |
EDITOR="`which ed`" | |
VISUAL="`which vim`" | |
PAGER="/usr/bin/env sh -c 'col -b | `which view` - '" | |
export EDITOR VISUAL PAGER | |
### SDF MetaArray Specific Setup | |
if [ "`hostname`" = "ma.sdf.org" ]; then | |
PATH=/meta/i/irl/bin:/meta/i/irl/jython/bin:/meta/i/irl/perl5/bin:$PATH | |
MANPATH=/meta/i/irl/share/man:/meta/i/irl/perl5/man:$MANPATH | |
CLASSPATH='/meta/i/irl/jython/Lib/jars/*' | |
MAIL=/meta/mail/irl | |
alias bboard='ssh -t tty.sdf.org bboard' | |
alias com='ssh -t tty.sdf.org com' | |
alias oneliner='ssh -t.sdf.org tty oneliner' | |
alias maint='ssh -t tty.sdf.org maint' | |
VIRTUAL_ENV_DISABLE_PROMPT="true" | |
source ~/python/bin/activate | |
export PATH | |
export MANPATH | |
export CLASSPATH | |
export MAIL | |
fi | |
### SDF Cluster and SDF-EU Specific Setup | |
if [ "`domainname`" = "SDF" ] || [ "`hostname`" = "odin" ]; then | |
MAIL=/mail/`whoami` | |
export MAIL | |
fi | |
### University of Aberdeen's Central Unix System | |
### Specific Setup | |
if [ "`hostname`" = "sysa.abdn.ac.uk" ]; then | |
MAIL=$HOME/mbox | |
LD_LIBRARY_PATH=/usr/lib/ | |
PATH=/bin:/usr/bin:/usr/local/bin | |
export MAIL | |
export LD_LIBRARY_PATH | |
export PATH | |
fi | |
### Setup shell prompt | |
function precmd { | |
local TERMWIDTH | |
(( TERMWIDTH = ${COLUMNS} - 1 )) | |
### | |
# Truncate the path if it's too long. | |
PR_FILLBAR="" | |
PR_PWDLEN="" | |
local promptsize=${#${(%):---(%n@%m:%l)---()--}} | |
local pwdsize=${#${(%):-%~}} | |
if [[ "$promptsize + $pwdsize" -gt $TERMWIDTH ]]; then | |
((PR_PWDLEN=$TERMWIDTH - $promptsize)) | |
else | |
PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize)))..${PR_HBAR}.)}" | |
fi | |
} | |
setopt extended_glob | |
preexec () { | |
if [[ "$TERM" == "screen" ]]; then | |
local CMD=${1[(wr)^(*=*|sudo|-*)]} | |
echo -n "\ek$CMD\e\\" | |
fi | |
} | |
setprompt () { | |
### | |
# Need this so the prompt will work. | |
setopt prompt_subst | |
### | |
# See if we can use colors. | |
autoload colors zsh/terminfo | |
if [[ "$terminfo[colors]" -ge 8 ]]; then | |
colors | |
fi | |
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do | |
eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}' | |
eval PR_LIGHT_$color='%{$fg[${(L)color}]%}' | |
(( count = $count + 1 )) | |
done | |
PR_NO_COLOUR="%{$terminfo[sgr0]%}" | |
### | |
# See if we can use extended characters to look nicer. | |
typeset -A altchar | |
set -A altchar ${(s..)terminfo[acsc]} | |
PR_SET_CHARSET="%{$terminfo[enacs]%}" | |
PR_SHIFT_IN="%{$terminfo[smacs]%}" | |
PR_SHIFT_OUT="%{$terminfo[rmacs]%}" | |
PR_HBAR="-" | |
PR_ULCORNER="+" | |
PR_LLCORNER="+" | |
PR_LRCORNER="+" | |
PR_URCORNER="+" | |
### | |
# Decide if we need to set titlebar text. | |
case $TERM in | |
xterm*) | |
PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}' | |
;; | |
screen) | |
PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}' | |
;; | |
*) | |
PR_TITLEBAR='' | |
;; | |
esac | |
### | |
# Decide whether to set a screen title | |
if [[ "$TERM" == "screen" ]]; then | |
PR_STITLE=$'%{\ekzsh\e\\%}' | |
else | |
PR_STITLE='' | |
fi | |
### | |
# Finally, the prompt. | |
PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\ | |
$PR_CYAN$PR_SHIFT_IN$PR_ULCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\ | |
$PR_GREEN%(!.%SROOT%s.%n)$PR_GREEN@%m:%l\ | |
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_HBAR${(e)PR_FILLBAR}$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\ | |
$PR_MAGENTA%$PR_PWDLEN<...<%~%<<\ | |
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_URCORNER$PR_SHIFT_OUT\ | |
$PR_CYAN$PR_SHIFT_IN$PR_LLCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\ | |
%(?..$PR_LIGHT_RED%?$PR_BLUE:)\ | |
$PR_YELLOW%D{%H:%M}\ | |
$PR_LIGHT_BLUE:%(!.$PR_RED.$PR_WHITE)%#$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\ | |
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\ | |
$PR_NO_COLOUR ' | |
RPROMPT=' $PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_BLUE$PR_HBAR$PR_SHIFT_OUT\ | |
($PR_YELLOW%D{%a,%b%d}$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_CYAN$PR_LRCORNER$PR_SHIFT_OUT$PR_NO_COLOUR' | |
PS2='$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\ | |
$PR_BLUE$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT(\ | |
$PR_LIGHT_GREEN%_$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\ | |
$PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR ' | |
} | |
setprompt | |
### Set timezone | |
export TZ=Europe/London | |
### Make sudo preserve environment | |
alias sudo="sudo -E" | |
### Clear screen before sensible outputs | |
clear | |
### Eduroam configuration | |
if ( which ip &>/dev/null && ( ip -4 route show | grep default ) &>/dev/null ) ; then | |
EDUROAM=`ip -4 route show | grep default | awk '{ print $3 }' | sed 's/\./\t/g' | awk '{ if ( $1 == "137" && $2 == "50" ) print "eduroam"; else print "freedom" }'` | |
if [ "$EDUROAM" = "eduroam" ]; then | |
http_proxy=http://px.abdn.ac.uk:8080 | |
https_proxy=http://px.abdn.ac.uk:8080 | |
ftp_proxy=http://px.abdn.ac.uk:8080 | |
gopher_proxy=http://px.abdn.ac.uk:8080 | |
export http_proxy https_proxy ftp_proxy gopher_proxy | |
echo "========================================" | |
echo "Eduroam Detected!" | |
echo "HTTP Proxy: $http_proxy" | |
echo "HTTPS Proxy: $https_proxy" | |
echo "FTP Proxy: $ftp_proxy" | |
echo "Gopher Proxy: $gopher_proxy" | |
echo "========================================" | |
else | |
unset http_proxy https_proxy ftp_proxy gopher_proxy | |
export http_proxy https_proxy ftp_proxy gopher_proxy | |
echo "========================================" | |
echo "No Eduroam Detected!" | |
echo "========================================" | |
fi | |
fi | |
### Display calendar and greeting | |
cal -3 | |
echo | |
echo "Greetings, `whoami`!" | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment