aboutsummaryrefslogtreecommitdiffstats
path: root/home/root/common/core/zsh/zshrc
blob: 1d84aaf956257c3404970aaf646697effdfad817 (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
umask 022

eval $(dircolors)

# completion options
setopt LIST_PACKED MENU_COMPLETE
# expansion and globbing options
setopt NO_NOMATCH
# history options
setopt SHARE_HISTORY EXTENDED_HISTORY HIST_FCNTL_LOCK HIST_IGNORE_ALL_DUPS HIST_REDUCE_BLANKS HIST_SAVE_NO_DUPS
# input/output options
setopt PRINT_EXIT_VALUE RM_STAR_SILENT
# job control options
setopt LONG_LIST_JOBS NO_HUP
# zle options
setopt NO_BEEP

zstyle ':completion:*' menu select=5

bindkey -v
export KEYTIMEOUT=1

autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line

# always open tmux if interactive
[[ $- != *i* ]] && return
#[[ -z "$TMUX" ]] && (tmux -2 new-session -t default \; new-window || tmux -2 new-session -s default)
[[ -z "$TMUX" ]] && (tmux -2 attach -t default || tmux -2 new-session -s default)

# my Nix helpers
function nix-switch-generation {

	local gen=${1}

	if [[ -z "${gen}" ]]; then
		echo 'you must specify a generation ID!' >&2
		return 1
	fi

	nix-env --switch-generation ${gen} -p /nix/var/nix/profiles/system
	/nix/var/nix/profiles/system/bin/switch-to-configuration switch

}

function nix-depends {

	local pkg=${1}

	if [[ -z "${pkg}" ]]; then
		echo 'you must specify a packange name!' >&2
		return 1
	fi

	local host=$(hostname -s)

	cd /etc/nixos
	nix why-depends .\#nixosConfigurations.${host}.config.system.build.toplevel .\#nixosConfigurations.${host}.pkgs.${pkg} --derivation | cat
	cd ${OLDPWD}

}

function ntrace {

	if [[ -z ${argv} ]]; then
		echo 'you must specify a command to strace!' >&2
		return 1
	fi

	eval strace -f -e trace=network -s 10000 ${=argv[@]}

}

function wake {

	if [[ -z ${argv} ]]; then
		echo 'you must specify a host to wake!!' >&2
		return 1
	fi

	local host="${1}"

	case "${host}" in
		jupiter)
			host="8c:8c:aa:4e:e9:8c"
			;;
		neptune)
			host="38:f3:ab:59:08:10"
			;;
		saturn)
			host="38:f3:ab:59:06:e0"
			;;
		uranus)
			host="8c:8c:aa:4e:fc:aa"
			;;
		*)
			echo 'unknown host specified!' >&2
			return 1
			;;
	esac

	wol -vi 192.168.1.255 "${host}"

}

# prompt/theme shit
function precmd {

	local RC=${?}
	#local RC=${(%)RC-%?}
	
	print -nP '\n'
	
	# current user
	if [[ ${EUID} -eq 0 ]]; then
		print -nP '%{%S%F{red}%}%n%{%f%s%}'
	else
		print -nP '%{%F{magenta}%}%n%{%f%}'
	fi
	
	print -nP '@'
	
	# current host
	if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then
		print -nP '%{%F{yellow}%}%m%{%f%}'
	else
		print -nP '%{%F{green}%}%m%{%f%}'
	fi
	
	# connected terminal
	print -nP '/%{%U%}%l%{%u%} '
	
	# cwd
	print -nP '%{%F{cyan}%}%~%{%f%} '
	
	# job count
	JOBCOUNT='%j'
	if [[ ${(%)JOBCOUNT} -gt 0 ]]; then
		print -nP 'j=%{%F{yellow}%}%j%{%f%} '
	fi
	
	# previous return code
	if [[ ${RC} -ne 0 ]]; then
		print -nP 'rc=%{%F{red}%}'
		echo -n "${RC}"
		print -nP '%{%f%} '
	else
		print -nP 'rc=%{%F{green}%}'
		echo -n "${RC}"
		print -nP '%{%f%} '
	fi
	
	# time stamp
	print -P '%{%F{cyan}%}%D{%FT%T%z}%{%f%}'

}

PS1='%# '