-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshrc
128 lines (109 loc) · 3.49 KB
/
shrc
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
# shellcheck disable=SC2164 # cd is handled
# shellcheck disable=SC2142 # not an error
# shellcheck disable=SC2059 # these variables are part of fmtstr
# shellcheck disable=SC2016 # we don't want the code to be run at definition
# UUID to check if this file has been sourced
export SHRC_UUID='56751b2a-c93f-4b80-a324-c49574eea33b'
# color definitions and control codes
export undo='\033[0m'
export reset='\033[0m'
export red='\033[31m'
export green='\033[32m'
export blue='\033[34m'
export bold='\033[1m'
export cross='\033[9m'
export ital='\033[3m'
export over='\033[53m'
export under='\033[4m'
export B='\033[1m'
export R='\033[0m'
# RGB foreground and background
rgb() { printf "\033[38;2;${1};${2};${3}m"; }
rgbb() { printf "\033[48;2;${1};${2};${3}m"; }
# 256 color fore/back ground
colf() { printf "\033[38;5;${1}m"; }
colb() { printf "\033[48;5;${1}m"; }
# append to PATH
append_path() {
test -d "$1" || return 1
case ":${PATH}:" in
*:"$1":*) : ;;
*) PATH="${PATH:+$PATH:}$1" ;;
esac
}
# set envars
append_path "${HOME}/.sh.d"
export PATH
export TMPDIR='/tmp'
export EDITOR='vim'
export nl='
'
export tab=' '
export tb=' '
export sp=' '
export DEFAULT_IFS="${sp}${tb}${nl}"
export FZF_DEFAULT_COMMAND='rg --files --hidden --follow'
export TERM=xterm-256color
export XDG_CONFIG_HOME="${HOME}/.config"
export XDG_CACHE_HOME="${HOME}/.cache"
export now='date +"%d_%b_%y__%H:%M:%S"'
export DEBUG=false
TTY=$(tty)
export TTY
# error handing primitive; invoke via `die` alias
fatal_string="${bold}Fatal error [${red}%s${reset}${bold}] on line ${green}%s${reset}${bold} in '${blue}%s${reset}${bold}':${reset} %s\n"
__errex() {
printf "${fatal_string}" \
"${1:-"?"}" \
"${2:-"?"}" \
"${3:-"undetermined script"}" \
"${4:-"undetermined error"}" >&2 ;
exit "${1:-1}"
}
# debug handling primitive; invoke via `debug` alias
__debug() {
"${DEBUG}" &&
printf 'Debug line %s in '"'"'%s'"'"': %s\n' \
"${1:-"?"}" \
"${2:-"undetermined script"}" \
"${3:-"(empty debug message)"}" >&2 ;
}
# message handling primitive; invoke via `msg|warn` alias
message_string="${bold}[${reset}${blue}%s${reset}:%s${bold}]${reset} ${bold}%s:${reset} %s\n"
__message() {
printf "${message_string}" \
"${2:-"script"}" \
"${3:-"?"}" \
"${1:-"message"}" \
"${4:-"(empty $1)"}" >&2 ;
}
# error message primitive; invoke via `error` alias
error_string="${bold}[${reset}${blue}%s${reset}:%s${bold}]${reset} ${bold}%s[${red}${bold}%s${reset}${bold}]:${reset} %s\n"
__error() {
printf "${error_string}" \
"${2:-"script"}" \
"${3:-"?"}" \
"${1:-"error"}" \
"${4:-"?"}" \
"${5:-"(empty error)"}" >&2 ;
}
# suppress output, get only error code
quiet() { "$@" >/dev/null 2>&1 ;}
ok() { "$@" >/dev/null 2>&1 ;}
# suppress error code, get only output
noerr() { "$@" 2>/dev/null || : ;}
# printf shortcuts
out() { printf '%s\n' "$@" ;}
raw() { printf '%s\n' "$*" ;}
alias die='__errex "$?" "${LINENO}" "$0"'
alias debug='__debug "${LINENO}" "$0"'
alias msg='__message message "$0" "${LINENO}"'
alias warn='__message warning "$0" "${LINENO}"'
alias error='__error error "$0" "${LINENO}" "$?"'
alias scr='screenkey -g 400x400+1500+600'
alias sx='startx'
alias bb='bc -l <<X'
set_control_escape() {
setxkbmap -option ctrl:nocaps # turn CapsLock into Ctrl
xcape -e 'Control_L=Escape' # turn tapping Ctrl into Escape
}