configs  Check-in [c3587c83a7]

Overview
Comment:zshrc: Modernize and backport a bunch from fish
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c3587c83a790f03414e2ba3ad65ca71b7d5f19ba5b6167500ebcfddb43eac630
User & Date: js 2020-02-14 01:40:47
Context
2020-02-14
02:32
zshrc: Match fish prompt check-in: 639c6d7de4 user: js tags: trunk
01:40
zshrc: Modernize and backport a bunch from fish check-in: c3587c83a7 user: js tags: trunk
2020-02-12
21:54
prompt_pwd.fish: Keep the initial / for dirs in / check-in: 9fabec2218 user: js tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to zshrc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export EDITOR="vim"
export PAGER="less"
export LS_COLORS='di=34:ow=44;37:tw=44;37:st=44;37:ex=31:su=7;31:sg=7;31:ln=33:or=7;33:pi=32:do=32:bd=35:cd=35:so=32:*.bz2=36:*.dmg=36:*.gz=36:*.gpg=36:*.rar=36:*.tar=36:*.tbz2=36:*.tgz=36:*.xz=36:*.zip=36:*.orig=90:*~=90'
LISTMAX=32768
WORDCHARS="*?[];!#~"
local grep=""
local grep_color="auto"
local fgrep=""
local ls=""
local ls_color="auto"
local ls_on_cd="yes"
local ls_on_init="no"

bindkey -v
# history-incremental-search-backward is much more useful than







<







1
2
3
4
5
6
7

8
9
10
11
12
13
14
export EDITOR="vim"
export PAGER="less"
export LS_COLORS='di=34:ow=44;37:tw=44;37:st=44;37:ex=31:su=7;31:sg=7;31:ln=33:or=7;33:pi=32:do=32:bd=35:cd=35:so=32:*.bz2=36:*.dmg=36:*.gz=36:*.gpg=36:*.rar=36:*.tar=36:*.tbz2=36:*.tgz=36:*.xz=36:*.zip=36:*.orig=90:*~=90'
LISTMAX=32768
WORDCHARS="*?[];!#~"
local grep=""
local grep_color="auto"

local ls=""
local ls_color="auto"
local ls_on_cd="yes"
local ls_on_init="no"

bindkey -v
# history-incremental-search-backward is much more useful than
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
setopt auto_pushd

autoload -U compinit
compinit -C

# Ignore case on completion
zstyle ':completion:*' matcher-list 'm:{A-Z}={a-z} m:{a-z}={A-Z}'





if [ -n "$grep" -o -n "$grep_color" ]; then
	if [ -z "$grep" ]; then
		if which ggrep &>/dev/null; then
			grep="ggrep"
		else
			grep="grep"
		fi
	fi
	[ -n "$grep_color" -a "$grep_color[1]" != "-" ] && \
		grep_color="--color=$grep_color"
	alias grep="$grep $grep_color"
fi

if [ -n "$fgrep" -o -n "$grep_color" ]; then
	if [ -z "$fgrep" ]; then
		if which ggrep &>/dev/null; then
			fgrep="ggrep -F"
		else
			fgrep="fgrep"
		fi
	fi
	[ -n "$grep_color" -a "$grep_color[1]" != "-" ] && \
		grep_color="--color=$grep_color"
	alias fgrep="$fgrep $grep_color"
fi

if [ -n "$ls" -o -n "$ls_color" ]; then
	if [ -z "$ls" ]; then
		if which gls &>/dev/null; then
			ls="gls"
		else
			ls="ls"
		fi
	fi
	[ -n "$ls_color" -a "$ls_color[1]" != "-" ] && \
		ls_color="--color=$ls_color"
	alias ls="$ls $ls_color"
fi

if [ "$ls_on_cd" = "yes" ]; then
	chpwd() {
		ls
	}
fi

if [ "$TERM_PROGRAM" = "Apple_Terminal" ]; then
	update_terminal_cwd() {
		printf '\e]7;%s\a' "file://$HOSTNAME${PWD// /%20}"
	}
else


	update_terminal_cwd() {
	}
fi



set_prompt() {
	PS1="%m:%c$@%B%(!.#.$)%b "
	PS2="%B>%b "
	RPS1="%(1j.%{$(print "\e[1;33m")%}%j%{$(print "\e[0m")%}.)"
	RPS1+="%(?..%(1j. .)%{$(print "\e[1;31m")%}%?%{$(print "\e[0m")%})"
	RPS2="%(1_.%{$(print "\e[1;30m")%}(%_%)%{$(print "\e[0m")%}.)"
}
set_prompt

_precmd() {
	update_terminal_cwd

	local branch_name
	branch_name="$(git symbolic-ref HEAD 2>/dev/null)"
	branch_name="${branch_name##refs/heads/}"
	if [ -n "$branch_name" -a "$branch_name" != "master" ]; then
		local branch
		branch="%{$(print "\e[1;30m")%}("
		branch+="%{$(print "\e[0;36m")%}$branch_name"
		branch+="%{$(print "\e[1;30m")%})%{$(print "\e[0m")%}"
		set_prompt "$branch"
	else
		set_prompt
	fi

}

case $TERM in
	aterm|Eterm|rxvt*|uxterm*|xterm*)

		# Use set_title if you want to change the term title
		set_title() {
			# Without this, precmd would override it
			precmd() {
				_precmd
			}
			print -Pn "\e]0;$@\a"
		}

		unset_title() {
			precmd() {
				print -Pn "\e]0;%m:%c\a"
				_precmd
			}
		}

		unset_title
		;;
	*)
		precmd() {
			_precmd
		}
		;;
esac

extr() {
	for i in $@; do
		case $i in
			*.7z)








>
>
>
>

<
|
<
<
<
<
<
|



<
<
<
<
<
<
<
<
<
<
<
|
<


<
|
<
<
<
<
<
|



|
|
<
<
|
<
|
|
|
|
|
<
>
>
|
<
<
>
>










|


|
<
|
|
<
|


<
<
<

>




<



|
<
<






|






|
<
<







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
setopt auto_pushd

autoload -U compinit
compinit -C

# Ignore case on completion
zstyle ':completion:*' matcher-list 'm:{A-Z}={a-z} m:{a-z}={A-Z}'

__find_command() {
	which "$1" &>/dev/null && echo "$1" || echo "$2"
}

if [ -n "$grep" -o -n "$grep_color" ]; then

	: ${grep:=$(__find_command ggrep grep)}





	[ -n "$grep_color" -a "$grep_color[1]" != - ] &&
		grep_color="--color=$grep_color"
	alias grep="$grep $grep_color"
fi











alias fgrep="grep -F"


if [ -n "$ls" -o -n "$ls_color" ]; then

	: ${ls:=$(__find_command gls ls)}





	[ -n "$ls_color" -a "$ls_color[1]" != - ] &&
		ls_color="--color=$ls_color"
	alias ls="$ls $ls_color"
fi
[ "$ls_on_cd" = yes ] && chpwd() { ls }
[ "$ls_on_init" = yes ] && ls




case $TERM_PROGRAM in
	Apple_Terminal)
		__update_terminal_cwd() {
			printf '\e]7;%s\a' "file://$HOSTNAME${PWD// /%20}"
		}

		;;
	*)
		__update_terminal_cwd() {}


		;;
esac

set_prompt() {
	PS1="%m:%c$@%B%(!.#.$)%b "
	PS2="%B>%b "
	RPS1="%(1j.%{$(print "\e[1;33m")%}%j%{$(print "\e[0m")%}.)"
	RPS1+="%(?..%(1j. .)%{$(print "\e[1;31m")%}%?%{$(print "\e[0m")%})"
	RPS2="%(1_.%{$(print "\e[1;30m")%}(%_%)%{$(print "\e[0m")%}.)"
}
set_prompt

__precmd() {
	update_terminal_cwd

	local branch_name=$(git symbolic-ref HEAD 2>/dev/null)

	branch_name=${branch_name##refs/heads/}
	if [ -n "$branch_name" -a "$branch_name" != master ]; then

		local branch="%{$(print "\e[1;30m")%}("
		branch+="%{$(print "\e[0;36m")%}$branch_name"
		branch+="%{$(print "\e[1;30m")%})%{$(print "\e[0m")%}"



	fi
	set_prompt $branch
}

case $TERM in
	aterm|Eterm|rxvt*|uxterm*|xterm*)

		# Use set_title if you want to change the term title
		set_title() {
			# Without this, precmd would override it
			precmd() { __precmd }


			print -Pn "\e]0;$@\a"
		}

		unset_title() {
			precmd() {
				print -Pn "\e]0;%m:%c\a"
				__precmd
			}
		}

		unset_title
		;;
	*)
		precmd() { __precmd }


		;;
esac

extr() {
	for i in $@; do
		case $i in
			*.7z)
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
			*.tbz | *.tbz2 | *.tar.bz2)
				bzcat $i | ofarc -ttar -x -
				;;
			*.tgz | *.tar.gz)
				ofarc -x $i
				;;
			*.txz | *.tar.xz)
				xzcat $i | tar xfv -
				;;
			*.rar)
				unrar x $i
				;;
			*.zip)
				ofarc -x $i
				;;







|







127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
			*.tbz | *.tbz2 | *.tar.bz2)
				bzcat $i | ofarc -ttar -x -
				;;
			*.tgz | *.tar.gz)
				ofarc -x $i
				;;
			*.txz | *.tar.xz)
				xzcat $i | ofarc -ttar -x -
				;;
			*.rar)
				unrar x $i
				;;
			*.zip)
				ofarc -x $i
				;;
189
190
191
192
193
194
195
196
197
198











199





200



201










202

203





204
205
206
	done
}
for ext in 7z lha tar tbz tbz2 tar.bz2 tgz tar.gz txz tar.xz rar zip bz2 gz xz
do
	alias -s "$ext=extr"
done

[ "$EDITOR" = "vim" ] && alias vi=vim
which gpg2 &>/dev/null && alias gpg=gpg2












[ "$ls_on_init" = "yes" ] && ls









function ixio() {










	curl -F 'f:1=<-' ix.io

}






unset fgrep grep grep_color ls ls_color ls_on_cd ls_on_init
unset HISTFILE







|


>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>

>
>
>
|
>
>
>
>
>
>
>
>
>
>
|
>

>
>
>
>
>



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
	done
}
for ext in 7z lha tar tbz tbz2 tar.bz2 tgz tar.gz txz tar.xz rar zip bz2 gz xz
do
	alias -s "$ext=extr"
done

[ "$EDITOR" = vim ] && alias vi=vim
which gpg2 &>/dev/null && alias gpg=gpg2

make() {
	case "$PWD" in
		# pkgsrc needs bmake and does not like MAKEFLAGS including -j.
		*/pkgsrc | */pkgsrc/*)
			MAKEFLAGS= =$(__find_command bmake make) $@
			;;
		*)
			=make $@
			;;
	esac
}

# pkgsrc does not like MAKEFLAGS including -j
which pkg_chk &>/dev/null && alias pkg_chk="MAKEFLAGS= pkg_chk"
which pkg_rolling-replace &>/dev/null &&
	alias pkg_rolling-replace="MAKEFLAGS= pkg_rolling-replace"
which url2pkg &>/dev/null && alias url2pkg="MAKEFLAGS= url2pkg"

alias gpg-ssh="SSH_AUTH_SOCK=$HOME/.gnupg/S.gpg-agent.ssh ssh"
alias gpg-ssh-add="SSH_AUTH_SOCK=$HOME/.gnupg/S.gpg-agent.ssh ssh-add"
alias gpg-sftp="SSH_AUTH_SOCK=$HOME/.gnupg/S.gpg-agent.ssh sftp"

__pw() {
	local clipboard
	if which pbcopy &>/dev/null; then
		clipboard=pbcopy
	elif which xclip &>/dev/null; then
		clipboard=xclip
	else
		echo "No clipboard handler found!"
		return 1
	fi

	cryptopassphrase $@ | tr -d '\n' | $clipboard
}
alias pw="__pw -k ~/.cryptopassphrase.key"
alias pws="__pw -k ~/.cryptopassphrase-server.key"

ixio() { curl -F 'f:1=<-' ix.io }
0x0st() { curl -F'file=@-' https://0x0.st }

unset fgrep grep grep_color ls ls_color ls_on_cd ls_on_init
unset HISTFILE