From 7d2c01f2b0a9843b02fde506decbe330dded1ba2 Mon Sep 17 00:00:00 2001 From: snow flurry Date: Sat, 6 Aug 2022 19:27:10 -0700 Subject: [PATCH] mkshrc: bash compatibility???? --- base/.bashrc | 1 + base/.mkshrc | 201 +++++++++++++++++++++++++++++++-------------------- 2 files changed, 122 insertions(+), 80 deletions(-) create mode 120000 base/.bashrc diff --git a/base/.bashrc b/base/.bashrc new file mode 120000 index 0000000..811decc --- /dev/null +++ b/base/.bashrc @@ -0,0 +1 @@ +.mkshrc \ No newline at end of file diff --git a/base/.mkshrc b/base/.mkshrc index 2d75f21..fbf025c 100644 --- a/base/.mkshrc +++ b/base/.mkshrc @@ -4,87 +4,9 @@ if [ -f /etc/shrc ]; then . /etc/shrc fi -export EDITOR=vim - -# Force 256color term for screen -if [ "$TERM" = "screen" ] ; then - TERM="screen-256color" - export TERM -fi - -export LANG= -export LC_ALL=en_US.UTF-8 - -## Ripped from a custom /etc/shrc, not very useful here -UID="$(id -u)" -if [ "$UID" -eq "0" ] ; then - PROMPT="#" - USER_COLOR='' -else - PROMPT="$" - USER_COLOR='' -fi - -get_ps1() { - rv=$? - if [ "$rv" -ne "0" -a "$rv" -ne "130" ] ; then - print -n "$rv | " - fi - if [ -n "$SSH_TTY" ] ; then - print -n "[SSH] " - fi - print -n "${USER_COLOR}${HOST%%.*}:"; - if [[ "${PWD#$HOME}" != "$PWD" ]] ; then - print -n "~${PWD#$HOME}" - else - print -n "$PWD" - fi - print -n "${USER_COLOR} ${PROMPT} " -} - -case "$-" in *i*) - # interactive mode settings go here - if /bin/test -z "${HOST}"; then - HOST="$(hostname)" - fi - PS1='$(get_ps1)' - set -o emacs - # This file is used by shells that might not support - # set -o tabcomplete, so check before trying to use it. - ( set -o tabcomplete 2>/dev/null ) && set -o tabcomplete - - alias gpg='gpg2' - alias ctop='xclip -selection clipboard -out | xclip -selection primary -in' - alias ptoc='xclip -selection primary -out | xclip -selection primary -in' - alias mutt='neomutt' - alias define='dict' - # Hack to bubble up profile, see bin/tmux-shim - alias tmux="$HOME/bin/tmux-shim" - - if [ "${KSH_VERSION:-notksh}" != "notksh" ] ; then - [[ "${KSH_VERSION}" == *"MIRBSD KSH"* ]] && bind '^L=clear-screen' - else - hn="$(hostname)" - PS1='${hn}:${PWD} \$ ' - fi - - calc() - { - echo "$@" | bc - } - - nconv() - { - if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then - echo "usage: nconv [from-base] [to-base] [num]" >&2 - return 1 - fi - - echo "obase=$2; ibase=$1; $3" | bc - } - ;; -esac +export EDITOR=nvim +## Extra paths if [ -f "$HOME/.cargo/env" ] ; then . $HOME/.cargo/env fi @@ -119,3 +41,122 @@ if [ -d "$HOME/Library/Android/sdk" ] ; then fi export PATH + +# Force 256color term for screen +if [ "$TERM" = "screen" ] ; then + TERM="screen-256color" + export TERM +fi + +export LANG= +export LC_ALL=en_US.UTF-8 + +## Ripped from a custom /etc/shrc, not very useful here +if [ -z "$UID" ] ; then + UID="$(id -u)" +fi + +BRL="[" +BRR="" +if [ -n "$BASH_VERSION" ] ; then + BRL="\\[\\\\033[" + BRR="\\]" +fi + +if [ "$UID" -eq "0" ] ; then + PROMPT="#" + USER_COLOR="${BRL}31m${BRR}" +else + PROMPT="$" + USER_COLOR="${BRL}96m${BRR}" +fi + +getrv() { + # HACK: Since the if statement in get_ps1 will clobber the old + # return value, KSH passes a cached version of the old val along + # so we can use it here. + rv=${1:-$?} + if [ "$rv" -ne "0" -a "$rv" -ne "130" ] ; then + printf "$rv | " + fi +} + +get_ps1() { + # Bash uses a static version of this, so we have to make a couple + # changes for post-processing + rv=$? + if [ -n "$BASH_VERSION" ] ; then + printf '$(getrv)' + else + getrv $rv + fi + + if [ -n "$SSH_TTY" ] ; then + printf "${BRL}33m${BRR}[SSH] " + fi + printf "${USER_COLOR}${HOST%%.*}:${BRL}39m${BRR}"; + if [ -n "$BASH_VERSION" ] ; then + printf "\w" + elif [[ "${PWD#$HOME}" != "$PWD" ]] ; then + printf "~${PWD#$HOME}" + else + printf "$PWD" + fi + printf "${USER_COLOR} ${PROMPT}${BRL}0m${BRR} " +} + +case "$-" in *i*) + # interactive mode settings go here + echo "interactive" + if /bin/test -z "${HOST}"; then + HOST="$(hostname)" + fi + PS1='$(get_ps1)' + set -o emacs + + # This file is used by shells that might not support + # set -o tabcomplete, so check before trying to use it. + ( set -o tabcomplete 2>/dev/null ) && set -o tabcomplete + + if command -v xclip >/dev/null ; then + alias ctop='xclip -selection clipboard -out | xclip -selection primary -in' + alias ptoc='xclip -selection primary -out | xclip -selection primary -in' + fi + + alias define='dict' + + if command -v nvim >/dev/null ; then + alias vim='nvim' + fi + + # Hack to bubble up profile, see bin/tmux-shim + alias tmux="$HOME/bin/tmux-shim" + + # Set bash PS1 + if [ -n "$BASH_VERSION" ] ; then + PS1="$(get_ps1)" + export PS1 + elif [ "${KSH_VERSION:-notksh}" != "notksh" ] ; then + [[ "${KSH_VERSION}" == *"MIRBSD KSH"* ]] && bind '^L=clear-screen' + else + hn="$(hostname)" + PS1='${hn}:${PWD} \$ ' + fi + + # Tiny helper functions + calc() + { + echo "$@" | bc + } + + nconv() + { + if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then + echo "usage: nconv [from-base] [to-base] [num]" >&2 + return 1 + fi + + echo "obase=$2; ibase=$1; $3" | bc + } + ;; +esac