-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_aliases
157 lines (135 loc) · 4.48 KB
/
bash_aliases
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
# ~/.bash_aliases: sourced by ~/.bashrc
# echo "### .bash_aliases at `date`"
# Shortcut commands
alias catc='egrep -h ^[[:space:]]*#\|^\;'
alias catn='egrep -hv ^$\|^[[:space:]]*#\|^\;'
alias cls='clear'
alias cpr='cp -Rp'
alias df='df -Hl'
alias du='du -sh'
alias hgr='history | egrep'
alias hgrt='_hgrt'
alias ht='history | cut -c 8- | tail'
alias more='less'
alias psx='ps -ef | head -1; ps -ef | grep'
alias sttysane='stty sane; stty iexten erase "^?" kill ^U intr ^C susp ^Z'
if type -p shfmt >/dev/null; then
alias shf='shfmt -i 4 -s'
alias shfd='shfmt -d -i 4 -s'
alias shff='shfmt -f'
alias shfl='shfmt -i 4 -s -l'
fi
# Prompts
alias ps1-T='export PS1="${TBAR}${BE_COLOR}\t \u@\h:\! \$${NO_COLOR} "' # Time & history number
alias ps1-t='export PS1="${TBAR}${BE_COLOR}\t \u@\h: \$${NO_COLOR} "' # Time without history number
alias ps1-l='export PS1="${TBAR}${BE_COLOR}\u@\h.local:\w \$${NO_COLOR} "' # Long path
alias ps1-s='export PS1="${TBAR}${BE_COLOR}\u@\h:\W \$${NO_COLOR} "' # Short path
alias ps1-n='export PS1="${TBAR}${BE_COLOR}\u@\h: \$${NO_COLOR} "' # No path
alias ps1-0='export PS1="${TBAR}${BE_COLOR}\u: \$${NO_COLOR} "' # No host
# git prompt
alias ps1-g='export PS1="${TBAR}${BE_COLOR}\t \u@\h:\W ${GPROMPT}${BE_COLOR}\$${NO_COLOR} "'
# iTerm tab titles
alias psi-0='export PROMPT_COMMAND='\''echo -ne "\033]0;\007"'\'''
alias psi-d='export PROMPT_COMMAND='\''echo -ne "\033]0;${PWD##*/}\007"'\'''
# TERM number of color settings
alias xt-16='export TERM=xterm'
alias xt-88='export TERM=xterm-88color'
alias xt-256='export TERM=xterm-256color'
# We can only do --color=auto on Linux
if [ $(uname -s) == "Linux" ]; then
COLOR_AUTO="--color=auto"
COLOR_ALWAYS="--color=always"
# These aliases only make sense if on Linux
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# Directory listings
# normal
alias ls='ls $COLOR_AUTO'
alias lsa='ls -A $COLOR_AUTO'
# with special chars to indicate file type
alias l='ls -CF'
alias la='ls -AF'
# If exa is installed
if type -p exa >/dev/null; then
alias ll='exa --git -s Name --colour=always -lg'
alias lla='exa --git -s Name --colour=always -lga'
alias llh='_lwh' # Most recent 20
alias llt='_lwt' # Today only
alias llr='exa --git -s Name --colour=always -lgR' # Recurse
alias lls='exa --git -s size -r --colour=always -lg' # size
# Dirs first, then by extension - both without & with gitignored files
alias lw='exa --git --git-ignore --group-directories-first -s ext --colour=always -lg'
alias lwg='exa --git --group-directories-first -s ext --colour=always -lg'
else
alias ll='ls -l $COLOR_AUTO'
alias lla='ls -lA $COLOR_AUTO'
alias llh='_llh' # Most recent 20
alias llt='_llt' # Today only
alias llr='ls -lR $COLOR_AUTO'
alias lls='_lls' # size
fi
# ssh shortcuts to various systems
# p m g
#
# Must use == not =~ to account for Bash 2.x
if [[ "$(uname -n)" == *[Ll]ocal ]]; then
ssh-ho='ssh [email protected] $@'
ssh-ir='ssh [email protected] $@'
fi
# Functions
findf() {
find . -name $*
}
finds() {
find . -name $*\*
}
findw() {
grep -h -o -E '\w+' $2 | sort -u | grep -i $1
}
_hgrt() {
history | egrep $@ | tail -20
}
_llh() {
ls -lt $COLOR_ALWAYS $@ | head -20
}
_llt() {
today=$(date "+%b %e")
ls -lt $COLOR_ALWAYS $@ | grep " $today "
}
_lls() {
ls -l $COLOR_ALWAYS $@ | grep -v ^d | sort -nr --key=5
}
_lwh() {
exa --git -s date -r --colour=always -lg $@ | head -20
}
_lwt() {
today=$(date "+%e %b")
exa --git -s date -r --colour=always -lg $@ | grep "$today "
}
# From various distros
colors() {
local fgc bgc vals seq0
printf "Color escapes are %s\n" '\e[${value};...;${value}m'
printf "Values 30..37 are \e[33mforeground colors\e[m\n"
printf "Values 40..47 are \e[43mbackground colors\e[m\n"
printf "Value 1 gives a \e[1mbold-faced look\e[m\n\n"
# foreground colors
for fgc in {30..37}; do
# background colors
for bgc in {40..47}; do
fgc=${fgc#37} # white
bgc=${bgc#40} # black
vals="${fgc:+$fgc;}${bgc}"
vals=${vals%%;}
seq0="${vals:+\e[${vals}m}"
printf " %-9s" "${seq0:-(default)}"
printf " ${seq0}TEXT\e[m"
printf " \e[${vals:+${vals+$vals;}}1mBOLD\e[m"
done
echo
echo
done
}
# end of .bash_aliases