summaryrefslogtreecommitdiffstats
path: root/zshrc
blob: 0d58ba4f95f3fc0b59bdc23fa66cb24073505859 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
fpath=(~/.zsh/completion $fpath)

# initialize zsh auto completion system
autoload -Uz compinit vcs_info; compinit
zmodload -i zsh/complist
autoload -U bashcompinit
bashcompinit

# history settings
#HISTFILE=~/.histfile
SAVEHIST=0
HISTSIZE=1000

source /etc/profile

# no beep
setopt prompt_subst autocd
unsetopt beep

# sane keybindings
bindkey -e

# define colors
BLACK="%{"$'\033[01;30m'"%}"
GREEN="%{"$'\033[01;32m'"%}"
RED="%{"$'\033[01;31m'"%}"
YELLOW="%{"$'\033[01;33m'"%}"
BLUE="%{"$'\033[01;34m'"%}"
BOLD="%{"$'\033[01;39m'"%}"
NORM="%{"$'\033[00m'"%}"

# my prefered prompt with color
# %n = Username
# %m = Hostname
# %~ = Current Directory
# %# = Shell Icon % for User, # for root
PROMPT="${GREEN}%n@%m ${BLUE}%~ "'${vcs_info_msg_0_}'"${BLUE}%# ${NORM}"

# continued prompt
PROMPT2="${BLUE}%_> ${NORM}"

# enable color in some commands
eval "`dircolors -b`"
export LS_COLORS="$LS_COLORS*.wmv=01;35:*.m4a=01;35:"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias less="less -r"
alias anki='anki -b'

swaymsg -t get_version >/dev/null 2>&1
if [ $? -eq 0 ] ; then
	# Use nvim in wayland for clipboard support
	alias vim="nvim -p"
	export EDITOR=nvim
	alias mpv="mpv --gpu-context=wayland"
else
	# vim: open multiple files in tabs by default
	alias vim="vim -p"
	export EDITOR=vim
fi

# method to load xilinx env
alias xilinx-env="emulate sh ; source /opt/Xilinx/14.7/ISE_DS/settings64.sh ; emulate zsh"
alias vivado-env="emulate sh ; source /opt/Xilinx/Vivado/2014.1/settings64.sh ; emulate zsh"

# debian quilt
alias dquilt="quilt --quiltrc=${HOME}/.quiltrc-dpkg"

# shortcut for some commands
alias l=ls
alias ll=ls -la
alias gq="background geeqie"
alias ev="background evince"
alias mpa="mpv -vo=null --ytdl-format=bestaudio"
alias cdg="cd \$(git root)"

alias ccugit="git -c sendemail.from='Sebastian Reichel <sebastian.reichel@collabora.com>' -c user.email='sebastian.reichel@collabora.com'"

# improved calender
alias cal="ccal -e -f"

# connect to USB tty with 115200 baud
alias cusb="picocom -b 115200 /dev/ttyUSB0"
alias cacm="picocom -b 115200 /dev/ttyACM0"
alias smoothie="picocom -b 115200 --echo /dev/smoothie0"

# suffix aliases
alias -s jpg="background gpicview"
alias -s gif="background gpicview"
alias -s png="background gpicview"
alias -s svg="background gpicview"
alias -s svgz="background eog"
alias -s pdf="background evince"
alias -s mkv="background mpv"
alias -s m4v="background mpv"
alias -s webm="background mpv"
alias -s ogg="background mpv"
alias -s ogv="background mpv"
alias -s wmv="background mpv"
alias -s mpg="background mpv"
alias -s avi="background mpv"
alias -s mp4="background mpv"
alias -s flv="background mpv"
alias -s exe="wine"
alias -s vala="vim"
alias -s txt="vim"
alias -s pho="gerbv"
alias -s doc="background libreoffice"
alias -s xlsx="background libreoffice"
alias -s odt="background libreoffice"
alias -s ods="background libreoffice"
alias -s docx="background libreoffice"
alias -s ppt="background libreoffice"
alias -s odp="background libreoffice"

# usage: 'aptitude search non-debian'
alias -g non-debian='~S~i!~Odebian'

# function to set terminal title
title() {
      if [[ $TERM == "xterm" || $TERM == "xterm-256color" || $TERM == "rxvt" || $TERM == "screen" ]]; then
		print -Pn  "\e]2;$*\a"
      fi
}

# set default programs
if [ $TERM = "xterm" ] ; then
export TERM=xterm-256color
elif [ $TERM = "screen" ] ; then
export TERM=screen-256color
fi
export PAGER=vimpager
export BROWSER=firefox

# path /sbin for ifconfig etc.
export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
export GOPATH=$HOME/src/go

# function to spawn a program in the background
background() {
	$1 $2 </dev/null >/dev/null 2>&1 &!
}

CHPWD_PROFILE='default'
function chpwd_profiles() {
    local -x profile

    zstyle -s ":chpwd:profiles:${PWD}" profile profile || profile='default'
    if (( ${+functions[chpwd_profile_$profile]} )) ; then
        chpwd_profile_${profile}
    fi

    CHPWD_PROFILE="${profile}"
    return 0
}
chpwd_functions=( ${chpwd_functions} chpwd_profiles )

function tmux_attached {
	if [ ! $TMUX ] ; then
		return 1
	fi

	TMUXSESSIONID=$(echo $TMUX | cut -d , -f 3)
	TMUXATTACHED=$(tmux ls -F "#{session_id}: #{?session_attached,1,0}" | grep "\$${TMUXSESSIONID}: " | sed "s~\$${TMUXSESSIONID}: ~~g")

	if [ "x$TMUXATTACHED" == "1" ] ; then
		return 0
	else
		return 1
	fi
}

# update title
function precmd {
	vcs_info
	title "%n@%m %~"

	if [ $TMUX ] ; then
		if [ tmux_attached ] ; then
			export `tmux showenv WINDOWID`
		else
			WINDOWID=""
		fi
	else
		export WINDOWID=$(pid2winid $PPID)
	fi

	if [[ "x$WINDOWID" != "x" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/terminal.png"
	fi
}

function preexec {
	title "$1"

	if [ $TMUX ] ; then
		export `tmux showenv WINDOWID`
	else
		export WINDOWID=$(pid2winid $PPID)
	fi

	if [ "x$WINDOWID" = "x" ] ; then
		return 0
	fi

	if [[ "$1" == "mutt" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/email.png"
	elif [[ `echo "$1" | grep "vim"` != "" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/vim.png"
	elif [[ `echo "$1" | grep "ssh"` != "" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/ssh.png"
	elif [[ `echo "$1" | grep "apt "` != "" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/install.png"
	elif [[ `echo "$1" | grep "mpv"` != "" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/mpv.png"
	elif [[ `echo "$1" | grep "mpa "` != "" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/mpv.png"
	elif [[ "$1" == "htop" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/htop.png"
	elif [[ `echo "$1" | grep "make"` != "" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/pkg-devel.png"
	elif [[ `echo "$1" | grep "git-pbuilder"` != "" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/pkg-devel.png"
	elif [[ `echo "$1" | grep "gbp buildpackage"` != "" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/pkg-devel.png"
	elif [[ `echo "$1" | grep "git "` != "" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/git.png"
	elif [[ "$1" == "cusb" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/serial.png"
	elif [[ "$1" == "picocom" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/serial.png"
	elif [[ "$1" == "bitbake" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/yocto.png"
	elif [[ "$1" == "ikhal" ]] ; then
		xseticon -id $WINDOWID "/home/sre/.zsh/icons/calendar.png"
	fi
}

# menus for mutt and less
zstyle ':completion:*:*:less:*' menu yes select
zstyle ':completion:*:*:mutt:*' menu yes select

# menu for Processes
zstyle ':completion:*:*:*:*:processes' menu yes select
zstyle ':completion:*:*:*:*:processes' force-list always

# use colors in completion
zstyle ':completion:*:default'         list-colors ${(s.:.)LS_COLORS}

# VCS Info
zstyle ':vcs_info:*' actionformats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
zstyle ':vcs_info:*' formats '%F{5}[%F{2}%b%F{5}]%f '
zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
zstyle ':vcs_info:*' enable bzr git hg svn

# tinyos directory specific configuration
zstyle ':chpwd:profiles:/home/sre/src/linux(|/|/*)' profile linux
zstyle ':chpwd:profiles:/home/sre/src/linux-next(|/|/*)' profile linux
zstyle ':chpwd:profiles:/home/sre/src/linux-droid(|/|/*)' profile linux
zstyle ':chpwd:profiles:/home/sre/src/linux-stable(|/|/*)' profile linux
zstyle ':chpwd:profiles:/home/sre/src/linux-hsi(|/|/*)' profile linux
zstyle ':chpwd:profiles:/home/sre/src/linux-n900(|/|/*)' profile linux
zstyle ':chpwd:profiles:/home/sre/src/linux-hackspace(|/|/*)' profile linux
zstyle ':chpwd:profiles:/home/sre/src/linux-misc-fixes(|/|/*)' profile linux
zstyle ':chpwd:profiles:/home/sre/src/linux-n950-display(|/|/*)' profile linux
zstyle ':chpwd:profiles:/home/sre/src/linux-power-supply(|/|/*)' profile linux
zstyle ':chpwd:profiles:/home/sre/src/zybo/linux(|/|/*)' profile linux
zstyle ':chpwd:profiles:/home/sre/src/n950/linux(|/|/*)' profile linux

chpwd_profile_linux() {
	[[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
	print "Switching to profile: $profile"

	export PATH="/usr/lib/ccache:$PATH"
	export CROSS_COMPILE="arm-linux-gnueabihf-"
	export ARCH=arm
}

chpwd_profile_default() {
	[[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
	print "chpwd(): Switching to profile: $profile"

	export PATH=$(echo $PATH | sed "s~/usr/lib/ccache:~~g")
	unset CROSS_COMPILE
	unset ARCH
}

# export some variables
export EMAIL="sre@ring0.de"
export DEBEMAIL="sre@debian.org"
export DEBSIGN_MAINT="sre@debian.org"
export DEBCHANGE_RELEASE_HEURISTIC=changelog

export LC_TIME=de_DE.UTF-8

# fix java fonts
export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=gasp'

# bash completion scripts
have()
{
	unset -v have
	PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null &&
	have="yes"
}

alias pmount="udevil mount"
alias pumount="udevil umount"
alias acs="ssh keyholder@ktt-acs"
alias acs-machining="ssh keyholder@ktt-acs-machining"
alias wpa_cli="wpa_cli -i wlp3s0"
alias real-mount='mount | grep -v -e "on /sys" -e "on /proc" -e "on /run" -e "on /dev"'
alias signal-desktop="docker run --rm -d -v /tmp/.X11-unix/:/tmp/.X11-unix -v $HOME/.signal:/root -e DISPLAY -e XAUTHORITY -v $XAUTHORITY:$XAUTHORITY --net=host signal"