-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path_shrc
58 lines (46 loc) · 1.48 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
# .sh/_shrc 20130315 - 20240511
# Copyright (C) 2015-2024 Mark Constable <[email protected]> (AGPL-3.0)
#shopt -s expand_aliases
[[ $DEBUG ]] && set -x
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/snap/bin:~/.sh/bin
SUDO=$([[ $(id -u) -gt 0 ]] && echo 'sudo ')
EDITOR=nano
COLOR=31
# Set the OS type
[[ -f /etc/os-release ]] && OSTYP=$(awk -F= '/^ID=/ {print $2}' /etc/os-release | sed 's/"//g')
# This needs to be before the first use of hostname for OpenWrt
if [[ $OSTYP == openwrt ]]; then
function getent {
if [[ $1 == passwd ]]; then
cat /etc/passwd
elif [[ $1 == group ]]; then
cat /etc/group
fi
}
function hostname {
local _host=$($SUDO uci get system.@system[0].hostname)
if [[ -z $1 ]]; then
echo $_host
elif [[ $1 == -f ]]; then
echo $_host.$($SUDO uci get dhcp.@dnsmasq[0].domain)
elif [[ $1 == -d ]]; then
$SUDO uci get dhcp.@dnsmasq[0].domain
fi
}
fi
LABEL=$(hostname)
# Import global aliases
[[ -f ~/.sh/lib/aliases ]] && . ~/.sh/lib/aliases
# Local custom aliases and env var overrides
[[ -f ~/.myrc ]] && . ~/.myrc
# Import managed env vars
[[ -f ~/.sh/lib/functions ]] && . ~/.sh/lib/functions
_HOST=$(hostname -f | tr 'A-Z' 'a-z')
if [[ -f ~/.vhosts/$_HOST ]]; then
. ~/.vhosts/$_HOST
else
sethost
fi
PS1="\[\033[1;${COLOR}m\]${LABEL} \w\[\033[0m\] "
export PATH SUDO MAILTO EDITOR COLOR LABEL PS1 # DEBUG?
[[ $DEBUG ]] && set +x