aboutsummaryrefslogtreecommitdiff
path: root/kshrc
diff options
context:
space:
mode:
Diffstat (limited to 'kshrc')
-rw-r--r--kshrc205
1 files changed, 113 insertions, 92 deletions
diff --git a/kshrc b/kshrc
index 4c42f3a..ae648ea 100644
--- a/kshrc
+++ b/kshrc
@@ -12,97 +12,93 @@
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
setaliases() {
- alias ls="ls -F";
- alias lt="ls -tF";
- alias ll="ls -lhF";
- alias llt="ls -tlhF";
- alias g="grep";
- alias m="more";
- alias j="jobs";
- alias p="pwd";
- alias c="column"
- alias ct="column -t"
- alias eg='grep -E'
- alias egv='grep -Ev'
- alias search='grep -niRIE'
- alias rot13="tr 'A-Za-z' 'N-ZA-Mn-za-m'"
- alias setxkbmap-list="man xkeyboard-config"
- # docker-getip $container_id
- alias docker-getip="docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'"
- alias xa='xargs -I{}'
- alias gdb='gdb -q'
- alias python='/usr/bin/env python3 -q'
- alias ncmpc='ncmpc -C -M'
- # Fun fact, Gnucash doesn't play nice when built against musl as a libc...
- # go figure
- alias gnucash_locale_fix='export LC_ALL=C; unset LANGUAGE; gnucash'
- pwgenForBanks() {
- set -x
- pwgen -r '[-#{};[:"'"'"'^()?><.|\/,`=]' -ncsy "$@"
- set +x
- }
-
- if [ "$(uname)" = "OpenBSD" ] ; then
- sockstat() {
- fstat | awk '
- BEGIN {
- OFS="\t";
- }
- {
- if ( NR == 1 ) {
- print($1, $2, $3, $5, $7, "ADDR");
- }
- if( $0 ~ /tcp|udp/ ) {
- if(!($0 ~ /[<-]-[->]/)) {
- l = $1 "\t" $2 "\t" $3 "\t" $5 "\t" $7 "\t";
- if($7 == "tcp") {
- services[$3] = l $9;
- } else if ($7 == "udp") {
- services[$3] = l $8;
- }
- }
- }
- }
- END {
- for(service in services) {
- print(services[service]);
+alias ls="ls -F";
+alias lt="ls -tF";
+alias ll="ls -lhF";
+alias llt="ls -tlhF";
+alias g="grep";
+alias m="more";
+alias j="jobs";
+alias p="pwd";
+alias c="column"
+alias ct="column -t"
+alias eg='grep -E'
+alias egv='grep -Ev'
+alias search='grep -niRIE'
+alias rot13="tr 'A-Za-z' 'N-ZA-Mn-za-m'"
+alias setxkbmap-list="man xkeyboard-config"
+# docker-getip $container_id
+alias docker-getip="docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'"
+alias xa='xargs -I{}'
+alias gdb='gdb -q'
+alias python='/usr/bin/env python3 -q'
+alias ncmpc='ncmpc -C -M'
+# Fun fact, Gnucash doesn't play nice when built against musl as a libc...
+# go figure
+alias gnucash_locale_fix='export LC_ALL=C; unset LANGUAGE; gnucash'
+
+if [ "$(uname)" = "OpenBSD" ] ; then
+sockstat() {
+ fstat | awk '
+ BEGIN {
+ OFS="\t";
+ }
+ {
+ if ( NR == 1 ) {
+ print($1, $2, $3, $5, $7, "ADDR");
+ }
+ if( $0 ~ /tcp|udp/ ) {
+ if(!($0 ~ /[<-]-[->]/)) {
+ l = $1 "\t" $2 "\t" $3 "\t" $5 "\t" $7 "\t";
+ if($7 == "tcp") {
+ services[$3] = l $9;
+ } else if ($7 == "udp") {
+ services[$3] = l $8;
}
}
- ' | column -t
+ }
}
- ! [ -x "$(which seq 2>/dev/null)" ] && alias seq="echo use jot(1)"
- fi
+ END {
+ for(service in services) {
+ print(services[service]);
+ }
+ }
+ ' | column -t
+}
+! [ -x "$(which seq 2>/dev/null)" ] && alias seq="echo \"use jot(1)\""
+fi
- if [ "$(uname)" = "Linux" ] ; then
- # Sets capslock to be another control key, only works with PS2 keyboards
- alias unfuck_capslock='setkeycodes 3a 29'
+if [ "$(uname)" = "Linux" ] ; then
+ # Sets capslock to be another control key, only works with PS2 keyboards
+ alias unfuck_capslock='setkeycodes 3a 29'
- alias bc='bc -q'
- fi
+ alias bc='bc -q'
+fi
}
setcoloraliases() {
- if [ "$(uname)" = "Linux" ] ; then
- alias ls="ls --color=auto -F";
- alias lm='ls -lh --color=force | more';
- elif [ "$(uname)" = "FreeBSD" ] ; then
- alias ls="ls -FG";
- alias lm='CLICOLOR_FORCE="1" ls -l | less -r';
- fi
+if [ "$(uname)" = "Linux" ] ; then
+ alias ls="ls --color=auto -F";
+ alias lm='ls -lh --color=force | more';
+elif [ "$(uname)" = "FreeBSD" ] ; then
+ alias ls="ls -FG";
+ alias lm='CLICOLOR_FORCE="1" ls -l | less -r';
+fi
- if echo "color test" | grep -q --color=auto "color test" >/dev/null 2>&1 ; then
- alias grep="grep --color=auto";
- alias egrep='grep -E --color=auto'
- alias search='grep -E --color=auto -rnI';
- fi
+if echo "color test" | grep -q --color=auto "color test" >/dev/null 2>&1 ; then
+ alias grep="grep --color=auto";
+ alias egrep='grep -E --color=auto'
+ alias search='grep -E --color=auto -rnI';
+fi
- #shellcheck disable=SC2139
- alias diff="$(command -v diff colordiff 2>/dev/null | tail -n 1)";
- alias t='tree -CdL'
+#shellcheck disable=SC2139
+alias diff="$(command -v diff colordiff 2>/dev/null | tail -n 1)";
+alias t='tree -CdL'
}
setsudoaliases() {
- # Prefer doas if available, as it's likely to be configured by me over sudo
+ # Prefer doas if available, as it's likely to be configured by \
+ # me over sudo
_sudo="$(command -v sudo 2>/dev/null | sed 1q)"
_doas="$(command -v doas 2>/dev/null | sed 1q)"
if [ -n "$_doas" ] ; then
@@ -130,7 +126,8 @@ umount"
# Only add aliases for commands that actually exist on our system
if [ -n "$_sudo" ] ; then
for _c in $_cmds ; do
- [ -n "$(command -v "$_c")" ] && eval "alias $_c=\"$_sudo $_c\""
+ [ -n "$(command -v "$_c")" ] && \
+ eval "alias $_c=\"$_sudo $_c\""
done
fi
case $_sudo in
@@ -138,7 +135,7 @@ umount"
esac
}
-# E.g. after `.mkshrc` is called, perhaps in `~/.mkshrc.local`
+# E.g. after `.kshrc` is called, perhaps in `~/.kshrc.local`
# export GOPATH=$HOME/code/gopath
# export GOROOT=$HOME/go/1.13.5
# set_go
@@ -152,6 +149,7 @@ set_go() {
export PATH="$_gobin:$PATH"
fi
}
+
_set_editor() {
export EDITOR="$1"
export VISUAL="$1"
@@ -164,6 +162,7 @@ _set_editor() {
#shellcheck disable=SC2139
alias e="$EDITOR"
}
+
set_editor() {
for editor in vim vi ed ; do
unalias "$editor" >/dev/null 2>&1
@@ -174,11 +173,14 @@ set_editor() {
break
done
}
+
set_pager() {
#shellcheck disable=SC2155
export PAGER="$(command -v cat more less 2>/dev/null | tail -n1)"
}
+
set_lang() {
+[ -z "$1" ] && return
export CHARSET="$1";
export LANG="$1";
}
@@ -197,6 +199,7 @@ randmacgen() {
| sed 's!^M$!!;s!\-!!g;s!\.!!g;s!\(..\)!\1:!g;s!:$!!'
echo ""
}
+
# First argument is the interface on which to scan
ipv6_local_hosts() {
if [ -n "$1" ] ; then
@@ -211,6 +214,7 @@ else
echo "You need to specify an interface"
fi
}
+
set_nocaps() {
setxkbmap -layout "us,de"
setxkbmap -option ctrl:nocaps
@@ -218,6 +222,7 @@ set_nocaps() {
setxkbmap -option numpad:microsoft
setxkbmap -option grp:alt_space_toggle
}
+
# Usage: dir_oct:file_oct path
setperms() {
_perm="$1"; shift
@@ -227,8 +232,25 @@ setperms() {
find "$@" -type d -print0 | xargs -0 chmod "$dir_perms"
}
+pwgenForBanks() {
+set -x
+pwgen -r '[-#{};[:"'"'"'^()?><.|\/,`=]' -ncsy "$@"
+set +x
+}
+
+setPrompt() {
+case $1 in
+date) export PS1='$(date "+%m.%d %H:%M") ${?##0}\$ ' ;;
+time) export PS1='$(date "+%H:%M") ${?##0}\$ ' ;;
+basic) export PS1='${?##0}\$ ' ;;
+esac
+}
+
+# Pull a list of all our SSH hostnames out of the config and
+# dump them to stdout
showsshhosts() {
- cat ~/.ssh/config ~/.ssh/inc/* 2>/dev/null | awk '/^[hH]ost /{$1=""; print $0}'
+cat ~/.ssh/config ~/.ssh/inc/* 2>/dev/null \
+ | awk '/^[hH]ost /{$1=""; print $0}'
}
showPasswordStore() {
@@ -274,7 +296,8 @@ _sys_load() {
_sys_uptime() {
# Took awhile to figure out, but this works on BSD as well
- uptime | sed -E -e's/^.*up[ ]+//g' -e's/^([^,]*),.*/\1/g' -e's/^([^ ]+)[ ]*(.).*/\1\2/g'
+ uptime | sed -E -e's/^.*up[ ]+//g' -e's/^([^,]*),.*/\1/g' \
+ -e's/^([^ ]+)[ ]*(.).*/\1\2/g'
}
@@ -661,22 +684,20 @@ elif [ -n "$KSH_VERSION" ] ; then
bind ^L=clear-screen
set -o emacs
- #shellcheck disable=SC2155
- [ -r ~/.password-store ] && \
- set -A complete_pass -- show find otp grep insert edit generate \
- rm mv cp \
- $(showPasswordStore ~/.password-store)
- [ -r ~/.ssh/config ] && \
- set -A complete_ssh -- -L -D -A -X \
+ [ -r ~/.password-store ] && set -A complete_pass -- show find otp grep \
+ insert edit generate rm mv cp \
+ $(showPasswordStore ~/.password-store)
+ [ -r ~/.ssh/config ] && set -A complete_ssh -- -L -D -A -X \
$(showsshhosts | awk '{print $1}')
+ set -A complete_setPrompt -- date time basic
# if you want PWD
- # export PS1='\u@\h \$PWD \$ '
- export PS1='\u@\h\$ '
+ # export PS1='${?##0}\u@\h \$PWD \$ '
+ export PS1='${?##0}\u@\h\$ '
if [ $(id -u) -eq 0 ] ; then
- export PS1='\h\$ '
+ export PS1='${?##0}\h\$ '
fi
elif [ "$SHELL" = "/bin/sh" ] && [ "$(uname)" = "FreeBSD" ] ; then