diff options
Diffstat (limited to 'kshrc')
| -rw-r--r-- | kshrc | 315 |
1 files changed, 10 insertions, 305 deletions
@@ -1,4 +1,4 @@ -# Copyright 2022 Mitchell Riedstra +# Copyright 2024 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 @@ -13,75 +13,25 @@ # 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 gi="grep -i"; alias m="more"; alias j="jobs"; alias p="pwd"; -alias c="column" -alias ct="column -t" -alias eg='grep -E' -alias egi='grep -Ei' -alias egv='grep -Ev' -alias egiv='grep -Eiv' -alias search='grep -niRIE' alias rot13="tr 'A-Za-z' 'N-ZA-Mn-za-m'" alias setxkbmap-list="man xkeyboard-config" -alias csi="rlwrap chicken-csi" # docker-getip $container_id [ -x "$(command -v docker)" ] && \ alias docker-getip="docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'" -alias xa='xargs -I{}' -[ -z "$(command -v gdb)" ] && \ - alias gdb='gdb -q' +[ -z "$(command -v gdb)" ] && alias gdb='gdb -q' #shellcheck disable=SC2139 -[ -x "$(command -v python3)" ] && \ - alias python="$(command -v python3) -q" -[ -x "$(command -v ncmpc)" ] && \ - alias ncmpc='ncmpc -C -M' -# Fun fact, Gnucash doesn't play nice when built against musl as a libc... -# go figure -[ -x "$(command -v gnucash)" ] && \ - alias gnucash_locale_fix='export LC_ALL=C; unset LANGUAGE; gnucash' +[ -x "$(command -v python3)" ] && alias python="$(command -v python3) -q" 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]); - } - } - ' | column -t -} -! [ -x "$(which seq 2>/dev/null)" ] && alias seq="echo \"use jot(1)\"" + ! [ -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' - alias bc='bc -q' fi } @@ -206,9 +156,9 @@ set_ksh_competion() { $(showPasswordStore ~/.password-store) #shellcheck disable=SC2046 - [ -x "$(command -v dpw)" ] && set -A complete_dpw_1 -- \ - show copy type list ls mv cp rm edit otp fnd find insert \ - && set -A complete_dpw_2 -- $(dpw list) + set -A complete_dpw_1 -- \ + show copy type list ls mv cp rm edit otp fnd find insert + set -A complete_dpw_2 -- $(dpw list) #shellcheck disable=SC2046 @@ -243,21 +193,6 @@ randmacgen() { echo "" } -# First argument is the interface on which to scan -ipv6_local_hosts() { -if [ -n "$1" ] ; then - interface="$1" - ping6 -c 3 "ff02::2%$interface" \ - | grep 'bytes from' \ - | awk '{print $4}' \ - | sort \ - | uniq \ - | sed -e's/:$//' -else - echo "You need to specify an interface" -fi -} - # Add a given path to the start of your $PATH if it doesn't already # exist path_preappend() { @@ -281,11 +216,9 @@ path_list() { } set_nocaps() { - setxkbmap -layout "us,de" setxkbmap -option ctrl:nocaps setxkbmap -option shift:breaks_caps setxkbmap -option numpad:microsoft - setxkbmap -option grp:alt_space_toggle } # Usage: dir_oct:file_oct path @@ -321,8 +254,7 @@ 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() { @@ -433,71 +365,6 @@ tmux new-session -s "$session" -n "$window_name" -c "$working_directory" \;\ "$@" } - -_tmux_dev() { -session="" -working_directory="$(pwd)" -window_name="editor" -while [ $# -gt 0 ] ; do case $1 in ---) shift ; break;; --s) session="$2" ; shift ; shift ;; --n) window_name="$2" ; shift ; shift ;; --w) working_directory="$2" ; shift ; shift ;; -*)echo "Invalid option $1" ; return ;; -esac ; done - -cd "$working_directory" || { echo "Cannot change to: $working_directory" ; return; } - -_tmux_session -s "$session" -w "$working_directory" -n "$window_name" \ - -- \ - send-keys -t 0 "$EDITOR" \; send-keys -t 0 Enter \;\ - new-window -n "shell" \;\ - new-window -n "git" \;\ - send-keys -t 0 "git status" \; send-keys -t 0 Enter \;\ - "$@" - -} - -_tmux_servers_split_commands() { -n=0 -server_cmds="" -while [ $# -gt 0 ] ; do - if [ $n -eq 0 ] ; then - server_cmds='send-keys "ssh \"'"$1"'\"" \; send-keys Enter \; ' - else - server_cmds="${server_cmds} split-window \; "'send-keys "ssh \"'"$1"'\"" \; send-keys Enter \; ' - fi - n="$(echo "$n+1" | bc)" - shift -done -echo "$server_cmds" -} - -_tmux_servers() { -session="" -working_directory="$HOME" -servers="" -layout="even-vertical" -while [ $# -gt 0 ] ; do case $1 in ---) shift ; break;; --s) session="$2" ; shift ; shift ;; --w) working_directory="$2" ; shift ; shift ;; --servers) servers="$2"; shift ; shift ;; --l) layout="$2"; shift ; shift ;; -*)echo "Invalid option $1" ; return ;; -esac ; done -cd "$working_directory" || { echo "Cannot change to: $working_directory" ; return; } - -layout="select-layout $layout ';' set-window-option synchronize-panes on ';'" - -eval _tmux_session -s "\$session" -w "\$working_directory" -n "main" \ - -- \ - $(_tmux_servers_split_commands $servers) \ - "$layout" \ - "\$@" \ - -} - scangit() { ref="origin/master" while [ $# -gt 0 ] ; do case $1 in @@ -586,154 +453,6 @@ pkg_switch_branch() { cp $_f ${_f}.orig sed -e's/quarterly/latest/' < ${_f}.orig > ${_f} } -# System setup `chroot`, useful mainly on Linux -syschroot() { - CHDIR=$1 - PROG=$2 - CUR_PS1="$PS1" - PS1="(CHROOT) # " - 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" \ - "$CHDIR/run" - PS1="$CUR_PS1" -} -pull() { - _f="" - _u="" - while [ $# -gt 0 ] ; do case $1 in - -f) _f="$2"; shift; shift ;; - -u) _u="$2"; shift; shift ;; - *) echo "pull usage: -f <output> -u <url>"; return ;; - esac ; done - echo "file: $_f" - echo "url: $_u" - if [ -z "$_f" ] || [ -z "$_u" ] ; then - echo "pull usage: -f <output> -u <url>"; return - fi - - if [ -n "$(command -v wget)" ] ; then - wget "$_u" -O "$_f" && return - fi - - if [ -n "$(command -v curl)" ] ; then - curl "$_u" -o "$_f" && return - fi - - if [ -n "$(command -v ftp)" ] && [ "$(uname)" = "OpenBSD" ] ; then - ftp -o "$_f" "$_u" && return - fi - - if [ -n "$(command -v fetch)" ] && [ "$(uname)" = "FreeBSD" ] ; then - fetch "$_u" -o "$_f" && return - fi - - - echo "Unable to fetch $_u" >&2 -} -pulldotfile() { - file="$1" - if [ -z "$file" ] ; then - echo "pulldotfile usage: <dotfilename>" - echo "Will pull from ${UPDATE_URL}/<dotfilename> and save to:" - #shellcheck disable=SC2088 - echo "~/.<dotfilename>" - return - fi - destfile="$(basename "${file}")" - pull -u "${UPDATE_URL}${file}" -f "$HOME/.${destfile}" -} -_make_ssh_dir_if_not_exists() { - auth_keys="$HOME/.ssh/authorized_keys" - if ! [ -d "$HOME/.ssh" ] ; then mkdir "$HOME/.ssh" ; fi - chmod 700 "$HOME/.ssh" - chmod 600 "$auth_keys" -} -_pullkeys() { - url="$1"; shift - _timestamp="$(timestamp)" - _make_ssh_dir_if_not_exists - auth_keys="$HOME/.ssh/authorized_keys" - mv "$auth_keys" "${auth_keys}.${_timestamp}" || \ - echo "Authorized Keys do not currently exist" - pull -u "$url" -f "$auth_keys" || \ - mv "${auth_keys}.${_timestamp}" "$auth_keys" - ssh-keygen -lf "$auth_keys" || \ - mv "${auth_keys}.${_timestamp}" "$auth_keys" - - chmod 600 "$auth_keys" -} -pullkeys() { - file="keys/$1"; shift; - url="${UPDATE_URL}${file}" - _pullkeys "$url" -} -pullkeys_github() { - _username="$1"; shift; - url="https://github.com/${_username}.keys" - _pullkeys "$url" -} -pulltermcolors() { - file="$HOME/bin/terminal-colors" - if ! [ -d "$HOME/bin" ] ; then - mkdir "$HOME/bin" - fi - pull -u "${UPDATE_URL}/util/terminal-colors" -f "$file" - chmod +x "$file" -} -updatetmuxconf() { - pulldotfile "tmux/tmux.conf" - pulldotfile "tmux/tmux_helper.sh" - if ! [ -e "$HOME/.tmux.conf.local" ] && [ "$(id -u)" -eq 0 ] ; then - # If I ever change the color from green this will have to be updated I guess - grep 'green' "$HOME/.tmux.conf" | sed -e's/green/red/g' > "$HOME/.tmux.conf.local" - elif ! [ -e "$HOME/.tmux.conf.local" ] ; then - touch "$HOME/.tmux.conf.local" - fi -} -updategitconf() { - file="gitconfig/$1" - pull -u "${UPDATE_URL}${file}" -f "$HOME/.gitconfig" -} -updateshell() { - pulldotfile "kshrc" - #shellcheck disable=SC1090 - . "$HOME/.kshrc" -} -updatenvim() { - OLDWD="$(pwd)" - #shellcheck disable=SC2164 - cd "$HOME" - nvimDest="$HOME/.config/nvim" - if ! [ -d "$nvimDest" ] ; then - mkdir -p "$nvimDest" - git clone "$NVIM_GIT_URL" "$nvimDest" - else - cd "$nvimDest" || { echo failed to cd "$nvimDest" ; return ; } - git pull --ff-only origin master - fi - cd "$OLDWD" -} -updatevimrc() { - OLDWD="$(pwd)" - #shellcheck disable=SC2164 - cd "$HOME" - mkdir -p "$HOME/.vim/autoload/" - pull -u "${UPDATE_URL}plug.vim" -f "$HOME/.vim/autoload/plug.vim" - pull -u "${UPDATE_URL}vimrc-full" -f "$HOME/.vimrc" - cd "$OLDWD" -} -updatevimrc_basic() { - pull -u "$VIM_BASIC_URL" -f ~/.vimrc -} - SHELL_CONFIG=".kshrc" COLOR=0 @@ -742,17 +461,13 @@ case "$TERM" in *256color) COLOR=1;; esac - path_preappend "$HOME/bin" -UPDATE_URL="https://git.riedstra.dev/mitch/dotfiles/plain/" -VIM_GIT_URL="https://git.riedstra.dev/mitch/vim-cfg" -NVIM_GIT_URL="https://git.riedstra.dev/mitch/nvim-config" -VIM_BASIC_URL="https://git.riedstra.dev/mitch/dotfiles/plain/vimrc" - PRELOAD="$HOME/${SHELL_CONFIG}.pre" LOCAL="$HOME/${SHELL_CONFIG}.local" +export PASSWORD_STORE_ENABLE_EXTENSIONS=true + # Don't put any variables below this, as they can't be overridden before the # functions if you do that @@ -764,20 +479,10 @@ set_pager # note that the use of set_editor and _set_editor on oksh may # change the input mode. ( set -o emacs ) after to go back set_editor # Also, opinionated, hope you like vim/vi -# set_go - -export PASSWORD_STORE_ENABLE_EXTENSIONS=true setaliases setsudoaliases -if [ -n "$DISPLAY" ] ; then - [ -x "$(command -v dmenu_askpass)" ] && \ - export SSH_ASKPASS=dmenu_askpass - checkSSHAgent -fi - - # Support various different shells if [ -n "$YASH_VERSION" ] ; then echo "Intentionally left blank" >/dev/null 2>&1 |
