summaryrefslogtreecommitdiffstats
path: root/.bashrc
blob: 4c86d046e88b8f2907553429fdd7e0c6c8030981 (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
# .bashrc

# Some minimal API expected by sourced files
_diralias () {
	test "$(pwd)" = "$(eval echo "$(dirs +1 2>/dev/null)")" && popd -n &>/dev/null
	test "$1" = "$(eval echo "$(dirs +0)")" || pushd "$1" >/dev/null
	pwd
}
diralias () { alias "$(basename "$1")=_diralias $1"; }

# Source the other common definitions
for f in /etc/bashrc ~/.bashrc-fedora ~/.bashrc-priv; do
	[ -f "${f}" ] && source "${f}" || :
done

# User specific aliases and functions

shopt -s histappend
HISTSIZE=5000
HISTCONTROL=ignoreboth

# subshell to avoid triggering DEBUG. (src: http://stuff.lhunath.com/.bashrc)
PROMPT_COMMAND='(history -a)'
PS1='\[\033[01;34m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '

# op(t)inioned commands
alias tree='tree -a'
alias mc='LESS="-RSX" mc'
alias tmux='tmux -2'
alias acka='ack -a --follow'

# debug, etc.
alias hist-del-last='history -d $(history 1 | cut -d" " -f2)'  # historical NOOP

# dir aliases (use either as "gmy" or "cd $(gmy)")
diralias ~/wrkspc/gmy
diralias ~/wrkspc/gwork


# debug, etc.

debug-argsep () {
	while [ $# -ne 0 ]; do
		echo $1;
		shift
	done
}

# proper functions

cdup () {
	local up="."
	for i in $(seq 1 $1); do up+="/.."; done
	cd "${up}" 2>/dev/null && pwd || :
	unset up
}

cdmk () {
	cd "$1" 2>/dev/null || { mkdir "$1"; cd "$1";}
}

# Jim Meyring's take on "display the programs with W and X memory"
# http://lists.fedoraproject.org/pipermail/devel/2013-April/181747.html
sec-wx-mem () {
	grep -lE '^[0-9a-f-]+ .wx' /proc/*/maps 2>/dev/null \
	  | perl -ne 'm!^(/proc/(\d+))/.*! and printf qq(%5d %s\n), $2, `cat $1/cmdline`' \
	  | tr '\0' ' '
}

ack-intersection () {
	[ $# -ne 2 ] && echo "usage: $FUNCNAME 1st-regexp 2nd-regexp" && return
	comm <(ack -al --follow "$1" | sort) <(ack -al --follow "$2" | sort) -12
}

hist-grep () {
	hist-del-last  # omit hist-grep invocation
	grep $* -- ~/.bash_history
}

img-diff () {
	[ $# -ne 2 ] && echo "usage: $FUNCNAME 1st-img 2nd-img" && return
	#xloadimage <(gm compare "$1" "$2" -highlight-color red -highlight-style threshold -file -)
	#xloadimage <(compare "$1" "$2" -highlight-color violet -lowlight-color darkgray -compose threshold -)
	#xloadimage <(compare "$1" "$2" -highlight-color violet -lowlight-color darkgray \
	#             -compose threshold jpg:- | convert jpg:- -fuzz 2% -fill red -opaque '#915e99' png:-)
	xloadimage <(compare "$1" "$2" -highlight-color violet -lowlight-color darkgray -compose threshold -)
}