From 88fb6eb07cae2b5ef069d35042ea78c59bde33db Mon Sep 17 00:00:00 2001 From: Benjamin Morrison Date: Fri, 17 Feb 2023 23:23:36 -0500 Subject: kshrc/completions --- .ksh_completions | 29 +++++++++++++++++++++++ .kshrc | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 .ksh_completions create mode 100644 .kshrc diff --git a/.ksh_completions b/.ksh_completions new file mode 100644 index 0000000..f6eab1d --- /dev/null +++ b/.ksh_completions @@ -0,0 +1,29 @@ +#shellcheck shell=ksh + +_SSH_HOSTS=$(awk '/^Host/ {print $2}' ~/.ssh/config) + +#shellcheck disable=2086 +set -A complete_mosh -- $_SSH_HOSTS + +#shellcheck disable=2086 +set -A complete_scp -- $_SSH_HOSTS + +#shellcheck disable=2086 +set -A complete_rsync -- $_SSH_HOSTS + +#shellcheck disable=2086 +set -A complete_ssh -- $_SSH_HOSTS + +_passwordStoreEntries() { + _passDir="$HOME/.password-store" + find "$_passDir" -type f -iname '*.gpg' | while read -r _line; do + _line="${_line##"$_passDir"}" + _line="${_line#/}" + _line="${_line%.gpg}" + echo "$_line" + done +} + +#shellcheck disable=SC2046 +set -A complete_pass -- -c show find otp grep insert edit generate rm mv cp $(_passwordStoreEntries) + diff --git a/.kshrc b/.kshrc new file mode 100644 index 0000000..3dd091a --- /dev/null +++ b/.kshrc @@ -0,0 +1,71 @@ +#shellcheck shell=ksh + +bind ^L=clear-screen +set -o emacs +export TERM=xterm-256color + +[ -f "$HOME/.ksh_completions" ] && . "$HOME/.ksh_completions" + +_ps1_ret_code() { + _ret=$? + [ -n "${_ret##0}" ] && echo " [${_ret}]" +} + +_ps1_git_branch() { + git_status="$(git status 2>/dev/null | awk '/On branch/ {print $3}')" + if [ "$git_status" != "" ]; then + echo " ($git_status)" + fi +} + +#shellcheck disable=SC2025 +export PS1='\u@\h \w`_ps1_git_branch``_ps1_ret_code`\$ ' + +dotfiles() { + #shellcheck disable=SC2068 + /usr/bin/git --git-dir "$HOME/.dotfiles/" --work-tree "$HOME" $@ +} + +pkgs() { + if [ -z "$1" ]; then + printf 'no package name specified\n' + return 1 + fi + /usr/bin/apt search --names-only "$1" +} + +grabfile() { + if [ -z "$1" ]; then + printf 'no file name specified\n' + return 1 + fi + xclip -selection clipboard "$1" +} + +snip() { + cat - | xclip -selection clipboard -i +} + +emacs() { + command emacs -nw "$1" +} + +dev_cd() { + if [ -z "$1" ]; then + cd "$HOME/dev" || return 1 + return 0 + fi + if [ -z "$2" ]; then + cd "$1" || return 1 + return 0 + fi + cd "$1/$2" || return 1 +} + +devg() { + dev_cd "$HOME/dev/github" "$1" +} +devs() { + dev_cd "$HOME/dev/srht" "$1" +} + -- cgit 1.4.1