aboutsummaryrefslogtreecommitdiff
path: root/mkshrc
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2019-09-12 22:16:59 -0400
committerMitch Riedstra <mitch@riedstra.us>2019-09-12 22:16:59 -0400
commit879d857e0eafa1f716d9e156862154baf49d7655 (patch)
tree917d88b41ba573cb9aabf2b3f3c7d0ac8d2b974b /mkshrc
parent142c972879f1055c7aa4844609e437aa9dd36370 (diff)
downloaddotfiles-879d857e0eafa1f716d9e156862154baf49d7655.tar.gz
dotfiles-879d857e0eafa1f716d9e156862154baf49d7655.tar.xz
Start cleanup process of my crusty shell configuration
Diffstat (limited to 'mkshrc')
-rw-r--r--mkshrc294
1 files changed, 110 insertions, 184 deletions
diff --git a/mkshrc b/mkshrc
index dbfa177..b03d4be 100644
--- a/mkshrc
+++ b/mkshrc
@@ -1,4 +1,4 @@
-# Copyright 2018 Mitchell Riedstra
+# Copyright 2019 Mitchell Riedstra
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
@@ -15,117 +15,80 @@
# If you wish to prevent non KSH shells from running this
# [ -z "$KSH_VERSION" ] && return
-# This will hopefully fix the bullshit with zsh
-if \
- [ $SHELL = "/bin/zsh" ] || \
- [ $SHELL = "/usr/bin/zsh" ] || \
- [ $SHELL = "/usr/local/bin/zsh" ] ; then
-# Bash doesn't like an empty if statement apparently
-printf ""
-else
-
-
-precmd() {
- typeset e=$?
-
- (( e )) && print -n "$e|"
-}
-set_ps1() {
- PS1='$(precmd)${BG}${ACCENT_C}${ACCENT_P}${USER_C}${USER:=$(id -un)}@$(hostname)${ACCENT_C}${ACCENT_P} ${ACCENT_P}${PATH_C}${PWD:-?}${ACCENT_C}${ACCENT_P}${END_C}
-${END_P} '
- export PS1;
-}
-set_root_ps1() {
-PS1='$(precmd)${BG}${ACCENT_C}${ACCENT_P}${HOST_C}$(hostname)${ACCENT_C}${ACCENT_P} ${ACCENT_P}${PATH_C}${PWD:-?}${ACCENT_C}${ACCENT_P}${END_C}
-${END_P} '
-export PS1;
-}
-# RED: 31, GREEN: 32, YELLOW: 33, BLUE: 34, MAGENTA: 35, CYAN: 36, WHITE: 37, GREY 38. and No color which is 0.
-set_prompt() {
- if [ `id -u` -eq 0 ] ; then
- # Previously
- # Red for root, and no username
- # PS1="$(hostname) \$PWD
- echo $TERM | grep "256color$" > /dev/null 2>&1
- if [ $? -eq 0 ] ; then
- BG=""
- ACCENT_C=""
- ACCENT_P="|"
- HOST_C=""
- PATH_C=""
- END_C=""
+# Restrict this to KSH only
+if ! [ -z "$KSH_VERSION" ] ; then
+ precmd() {
+ typeset e=$?
+
+ (( e )) && print -n "$e|"
+ }
+ set_ps1() {
+ PS1='$(precmd)${BG}${ACCENT_C}${ACCENT_P}${USER_C}${USER:=$(id -un)}@$(hostname)${ACCENT_C}${ACCENT_P} ${ACCENT_P}${PATH_C}${PWD:-?}${ACCENT_C}${ACCENT_P}${END_C}
+ ${END_P} '
+ export PS1;
+ }
+ set_root_ps1() {
+ PS1='$(precmd)${BG}${ACCENT_C}${ACCENT_P}${HOST_C}$(hostname)${ACCENT_C}${ACCENT_P} ${ACCENT_P}${PATH_C}${PWD:-?}${ACCENT_C}${ACCENT_P}${END_C}
+ ${END_P} '
+ export PS1;
+ }
+ # RED: 31, GREEN: 32, YELLOW: 33, BLUE: 34, MAGENTA: 35, CYAN: 36, WHITE: 37, GREY 38. and No color which is 0.
+ set_prompt() {
+ if [ `id -u` -eq 0 ] ; then
+ # Previously
+ # Red for root, and no username
+ # PS1="$(hostname) \$PWD
+ echo $TERM | grep "256color$" > /dev/null 2>&1
+ if [ $? -eq 0 ] ; then
+ BG=""
+ ACCENT_C=""
+ ACCENT_P="|"
+ HOST_C=""
+ PATH_C=""
+ END_C=""
+ set_root_ps1
+ END_P="#"
+ else
+ BG=""
+ ACCENT_C=""
+ ACCENT_P="|"
+ HOST_C=""
+ PATH_C=""
+ END_P="#"
+ fi
set_root_ps1
- END_P="#"
- else
- BG=""
- ACCENT_C=""
- ACCENT_P="|"
- HOST_C=""
- PATH_C=""
- END_P="#"
+ else
+ # Previously
+ # PS1="${USER:=$(id -un)}@$(hostname) \$PWD
+ echo $TERM | grep "256color$" > /dev/null 2>&1
+ if [ $? -eq 0 ] ; then
+ BG=""
+ ACCENT_C=""
+ ACCENT_P="|"
+ USER_C=""
+ PATH_C=""
+ END_C=""
+ END_P="%"
+ else
+ BG=""
+ ACCENT_C=""
+ ACCENT_P="|"
+ USER_C=""
+ PATH_C=""
+ END_C=""
+ END_P="$"
+ fi
+ set_ps1
fi
- set_root_ps1
- else
- # Previously
- # PS1="${USER:=$(id -un)}@$(hostname) \$PWD
- echo $TERM | grep "256color$" > /dev/null 2>&1
- if [ $? -eq 0 ] ; then
- BG=""
- ACCENT_C=""
- ACCENT_P="|"
- USER_C=""
- PATH_C=""
- END_C=""
- END_P="%"
- else
- BG=""
- ACCENT_C=""
- ACCENT_P="|"
- USER_C=""
- PATH_C=""
- END_C=""
- END_P="$"
- fi
- set_ps1
- fi
-}
-set_basic_prompt() {
- if [ $(id -u) -eq 0 ] ; then
- PS1='$(precmd)'"${USER:=$(id -un)}@$(hostname) \$PWD # "
- else
- PS1='$(precmd)'"${USER:=$(id -un)}@$(hostname) \$PWD $ "
- fi
- export PS1;
-}
-set_retro_prompt() {
- if ! [ -z "$BASH" ] ; then
- export PS1='\[$(set_my_title)\]\$ '
- elif ! [ -z "$KSH_VERSION" ] ; then
- export PS1='$ '
+ }
+ set_basic_prompt() {
if [ $(id -u) -eq 0 ] ; then
- export PS1='# '
- fi
- else
- export PS1='$ '
- if [ $(id -u) -eq 0 ] ; then
- export PS1='# '
+ PS1='$(precmd)'"${USER:=$(id -un)}@$(hostname) \$PWD # "
+ else
+ PS1='$(precmd)'"${USER:=$(id -un)}@$(hostname) \$PWD $ "
fi
- fi
-}
-set_super_basic_prompt() {
- alias cd=do_cd
-}
-do_cd() {
- builtin cd $@
- set_my_title
- pwd=${PWD##HOME}
- [ ${#pwd} -lt ${#PWD} ] && pwd="~$pwd"
- [ "$hostname" ] || hostname=$(hostname)
- PS1="$USER@$hostname:$pwd \$ "
- [ $(id -u) -eq 0 ] && PS1="$USER@$hostname:$pwd # "
-}
-
-# ZSH doesn't handle these functions all too well
+ export PS1;
+ }
fi
setaliases() {
@@ -139,7 +102,8 @@ setaliases() {
alias p="pwd";
alias c="column"
alias ct="column -t"
- alias eg='egrep'
+ 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"
@@ -149,13 +113,15 @@ setaliases() {
alias xa='xargs -I{}'
alias gdb='gdb -q'
alias bc='bc -q'
- alias python='python -q'
+ alias python='/usr/bin/env python3 -q'
# 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'
- # Linux specific but I don't care
- 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'
+ fi
}
setcoloraliases() {
@@ -179,75 +145,49 @@ setcoloraliases() {
}
setsudoaliases() {
- if which sudo > /dev/null 2>&1 && [ -x "$(which sudo)" ] ; then
+ # Prefer doas if available, as it's likely to be configured by me over sudo
+ _sudo="$(which doas sudo 2>/dev/null | sed 1q)"
+ if [ -x "$_sudo" ] ; then
# Package managers
# Isn't it amazing how many distros you end up using?
- alias apt-get='sudo apt-get'
- alias apt='sudo apt'
- alias apt-file='sudo apt-file'
- alias yum='sudo yum'
- alias dnf='sudo dnf'
- alias pacman='sudo pacman'
- alias xbps-install='sudo xbps-install'
- alias xbps-remove='sudo xbps-remove'
- alias pkg='sudo pkg'
+ alias apt-get="$_sudo apt-get"
+ alias apt="$_sudo apt"
+ alias apt-file="$_sudo apt-file"
+ alias yum="$_sudo yum"
+ alias dnf="$_sudo dnf"
+ alias pacman="$_sudo pacman"
+ alias xbps-install="$_sudo xbps-install"
+ alias xbps-remove="$_sudo xbps-remove"
+ alias pkg="$_sudo pkg"
+ alias pkg_add="$_sudo pkg_add"
# Filesystem utilities
- alias zfs='sudo zfs'
- alias zpool='sudo zpool'
- alias btrfs='sudo btrfs'
- alias mount='sudo mount'
- alias umount='sudo umount'
+ alias zfs="$_sudo zfs"
+ alias zpool="$_sudo zpool"
+ alias btrfs="$_sudo btrfs"
+ alias mount="$_sudo mount"
+ alias umount="$_sudo umount"
fi
}
# Usage debugstarttls $ipaddr:$port
debugstarttls() {
- openssl s_client -starttls smtp -crlf -connect $1 $2
+ openssl s_client -starttls smtp -crlf -connect "$1" "$2"
}
-
-set_retro() {
- set_retro_prompt
- unalias vi
- unalias vim
- unalias nvim
- # nvim has some serious issues with konsole and cool-retro-term
- export EDITOR="$(which vi nvi vim 2>/dev/null | tail -n1)"
- export VISUAL="$EDITOR"
- alias vi="$EDITOR"
- alias nvim="$EDITOR"
- export TERM="$(echo $TERM | sed -e's/-256color$//')"
-}
randmacgen() {
- # This seems to be needed on FreeBSD, I'll have to look into
- # exactly what is causing this and what the differences are
- LC_COLLATE=c
+ if [ "$(uname)" = "FreeBSD" ] ; then
+ LC_COLLATE=c
+ fi
tr -c -d '0123456789abcdef' < /dev/urandom \
| head -c 12 \
| sed 's!^M$!!;s!\-!!g;s!\.!!g;s!\(..\)!\1:!g;s!:$!!'
+ echo ""
}
# Run Steam
unfuck_steam() {
LD_PRELOAD='/usr/$LIB/libstdc++.so.6 /usr/$LIB/libgcc_s.so.1 /usr/$LIB/libxcb.so.1 /usr/$LIB/libgpg-error.so' /usr/bin/steam
}
-counter_figlet() {
-COUNTER="1";
-while true ; do
- figlet "$COUNTER";
- COUNTER="$(echo $COUNTER+1 |bc)";
- sleep 1;
- clear;
-done
-}
-counter_single_line() {
-COUNTER="1";
-while true ; do
- sleep 1;
- printf "\t$COUNTER\r";
- COUNTER="$(echo $COUNTER+1 |bc )";
-done
-}
# First argument is the interface on which to scan
ipv6_local_hosts() {
if ! [ -z $1 ] ; then
@@ -291,37 +231,23 @@ pkg_switch_branch() {
cp $_f ${_f}.orig
sed -e's/quarterly/latest/' < ${_f}.orig > ${_f}
}
-find_most_recent_python() {
-_python="$(which python2 2>/dev/null)"
-$_python -c 'import os
-
-max_mtime = 0
-for dirname,subdirs,files in os.walk("."):
- for fname in files:
- full_path = os.path.join(dirname, fname)
- mtime = os.stat(full_path).st_mtime
- if mtime > max_mtime:
- max_mtime = mtime
- max_dir = dirname
- max_file = fname
-
-print max_dir, max_file'
-}
# System setup `chroot`, useful mainly on Linux
syschroot() {
CHDIR=$1
PROG=$2
CUR_PS1="$PS1"
PS1="(CHROOT) # "
- mount -o bind /dev $CHDIR/dev
- mount -o bind /dev/pts $CHDIR/dev/pts
- mount -o bind /sys $CHDIR/sys
- mount -o bind /proc $CHDIR/proc
+ mount -t proc none "$CHDIR/proc"
+ mount -o bind /dev "$CHDIR/dev"
+ mount -o bind /dev/pts "$CHDIR/dev/pts"
+ mount -o bind /sys "$CHDIR/sys"
+ mount -o bind /run "$CHDIR/run"
if [ "$PROG" = "/bin/bash" ] ; then
PS1="(CHROOT) [ \u@\h \w ] # "
fi
- chroot $CHDIR $PROG
- umount $CHDIR/dev/pts $CHDIR/dev $CHDIR/sys $CHDIR/proc
+ chroot "$CHDIR" "$PROG"
+ umount "$CHDIR/dev/pts" "$CHDIR/dev" "$CHDIR/sys" "$CHDIR/proc" \
+ "$CHDIR/run"
PS1="$CUR_PS1"
}
@@ -346,7 +272,7 @@ set_my_title() {
}
_sys_memory() {
- [ -e $(which vmstat) ] && return
+ ! [ -e $(which vmstat) ] && return
if [ `uname` = "Linux" ] ; then
vmstat | tail -n1 | awk '{print $4/1024}' | sed -e's/\..*$//g'
elif [ `uname` = "FreeBSD" ] ; then