dotfiles2/base/.mkshrc

220 lines
5.2 KiB
Plaintext
Raw Normal View History

2022-08-06 05:16:17 +00:00
# (mk)shrc
if [ -f /etc/shrc ]; then
2022-08-07 02:46:26 +00:00
. /etc/shrc
2024-05-11 00:07:23 +00:00
elif [ -f /opt/shrc ]; then
. /opt/shrc
2022-08-06 05:16:17 +00:00
fi
2022-08-07 02:27:10 +00:00
export EDITOR=nvim
2024-05-11 00:07:23 +00:00
export KANIDM_URL="https://idm.qalico.net"
export KANIDM_USER="$USER"
# opt out of .NET telemetry
export DOTNET_CLI_TELEMETRY_OPTOUT=true
2022-08-07 02:27:10 +00:00
## Extra paths
# Python packages go here
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
# Homebrew (macOS)
if [ -d "/opt/homebrew" ] ; then
PATH="/opt/homebrew/bin:/opt/homebrew/sbin:/sbin:/usr/sbin:$PATH"
HOMEBREW_CASK_OPTS="--appdir=~/Applications"
2024-05-11 00:07:23 +00:00
PATH="/opt/homebrew/opt/ruby/bin:$PATH"
2022-08-07 02:27:10 +00:00
export HOMEBREW_CASK_OPTS
# x86 brew hack
if [ -d "$HOME/.x86_64/homebrew" ] ; then
brew86() {
PATH="$HOME/.x86_64/homebrew/bin:$PATH" arch -x86_64 $HOME/.x86_64/homebrew/bin/brew "$@"
}
fi
fi
2024-05-11 00:07:23 +00:00
if [ -f "$HOME/.cargo/env" ] ; then
PATH="$HOME/.cargo/bin:$PATH"
fi
2022-08-07 02:27:10 +00:00
# Flutter
if [ -d "$HOME/.opt/flutter" ] ; then
PATH="$HOME/.opt/flutter/bin:$PATH"
fi
2024-05-11 00:07:23 +00:00
# Perl local lib
if [ -d "$HOME/perl5/lib/perl5" ] ; then
eval $(perl -I ~/perl5/lib/perl5 -Mlocal::lib)
fi
2022-08-07 02:27:10 +00:00
# Android SDK (for VMs)
if [ -d "$HOME/Library/Android/sdk" ] ; then
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
PATH="$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/emulator:$ANDROID_SDK_ROOT/platform-tools:$PATH"
fi
export PATH
2022-08-06 05:16:17 +00:00
# Force 256color term for screen
if [ "$TERM" = "screen" ] ; then
TERM="screen-256color"
export TERM
fi
2024-05-11 00:07:23 +00:00
export LANG=en_US.UTF-8
export LC_ALL=
2022-08-06 05:16:17 +00:00
## Ripped from a custom /etc/shrc, not very useful here
2022-08-07 02:27:10 +00:00
if [ -z "$UID" ] ; then
UID="$(id -u)"
fi
BRL="["
BRR=""
if [ -n "$BASH_VERSION" ] ; then
BRL="\\[\\\\033["
BRR="\\]"
fi
2022-08-06 05:16:17 +00:00
if [ "$UID" -eq "0" ] ; then
PROMPT="#"
2022-08-07 02:27:10 +00:00
USER_COLOR="${BRL}31m${BRR}"
2022-08-06 05:16:17 +00:00
else
PROMPT="$"
2022-08-07 02:27:10 +00:00
USER_COLOR="${BRL}96m${BRR}"
2022-08-06 05:16:17 +00:00
fi
2022-08-07 02:27:10 +00:00
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
2024-05-11 00:07:23 +00:00
printf "${BRL}33m${BRR}%d${BRL}0m${BRR} » " "$rv"
2022-08-07 02:27:10 +00:00
fi
}
2022-08-06 05:16:17 +00:00
get_ps1() {
2022-08-07 02:27:10 +00:00
# Bash uses a static version of this, so we have to make a couple
# changes for post-processing
2022-08-06 05:16:17 +00:00
rv=$?
2022-08-07 02:27:10 +00:00
if [ -n "$BASH_VERSION" ] ; then
printf '$(getrv)'
else
getrv $rv
2022-08-06 05:16:17 +00:00
fi
2022-08-07 02:27:10 +00:00
2022-08-06 05:16:17 +00:00
if [ -n "$SSH_TTY" ] ; then
2024-05-11 00:07:23 +00:00
printf "${BRL}32m${BRR}SSH » "
2022-08-06 05:16:17 +00:00
fi
2024-05-11 00:07:23 +00:00
if _branch="$(git branch --show-current 2>/dev/null)" ; then
[ -z "${_branch}" ] && _branch="$(git rev-parse --short HEAD 2>/dev/null)"
printf "${BRL}97m${BRR}%s » " "${_branch}"
unset _branch
fi
printf "${USER_COLOR}${HOST%%.*} ${BRL}39m${BRR}";
2022-08-07 02:27:10 +00:00
if [ -n "$BASH_VERSION" ] ; then
printf "\w"
elif [[ "${PWD#$HOME}" != "$PWD" ]] ; then
printf "~${PWD#$HOME}"
2022-08-06 05:16:17 +00:00
else
2022-08-07 02:27:10 +00:00
printf "$PWD"
2022-08-06 05:16:17 +00:00
fi
2024-05-11 00:07:23 +00:00
printf "${USER_COLOR} \n${BRL}0m${BRR}${PROMPT} "
2022-08-06 05:16:17 +00:00
}
case "$-" in *i*)
2022-08-07 02:46:26 +00:00
# interactive mode settings go here
if /bin/test -z "${HOST}"; then
HOST="$(hostname)"
fi
2022-08-07 02:27:10 +00:00
PS1='$(get_ps1)'
2022-08-07 02:46:26 +00:00
set -o emacs
2022-08-07 02:27:10 +00:00
2022-08-07 02:46:26 +00:00
# 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
2022-08-06 05:16:17 +00:00
2022-08-07 02:27:10 +00:00
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
2022-08-06 05:16:17 +00:00
alias define='dict'
2022-08-07 02:27:10 +00:00
if command -v nvim >/dev/null ; then
alias vim='nvim'
fi
2022-08-06 05:16:17 +00:00
# Hack to bubble up profile, see bin/tmux-shim
alias tmux="$HOME/bin/tmux-shim"
2024-05-11 00:07:23 +00:00
# Alias dotfiles
alias dotfiles='git --git-dir=$HOME/.dotfiles.git/ --work-tree=$HOME'
2022-08-07 02:27:10 +00:00
# Set bash PS1
if [ -n "$BASH_VERSION" ] ; then
PS1="$(get_ps1)"
export PS1
elif [ "${KSH_VERSION:-notksh}" != "notksh" ] ; then
2022-08-06 05:16:17 +00:00
[[ "${KSH_VERSION}" == *"MIRBSD KSH"* ]] && bind '^L=clear-screen'
else
hn="$(hostname)"
PS1='${hn}:${PWD} \$ '
fi
2022-08-07 02:27:10 +00:00
# Tiny helper functions
2022-08-06 05:16:17 +00:00
calc()
{
echo "$@" | bc
}
2024-05-11 00:07:23 +00:00
## Bitwarden auto-unlock
if command -v bw >/dev/null ; then
if ! command -v jq >/dev/null ; then
cat <<EOF
** NOTE: jq isn't installed, default bw will be used
EOF
else
bw() {
status="$(command bw status | jq -r .status)"
if [ "$status" != "unlocked" ] ; then
export BW_SESSION="$(command bw unlock --raw)"
[ -z "$BW_SESSION" ] && return 1
fi
command bw "$@"
}
fi
fi
influx() {
real_influx="$(whereis -q influx)"
if [ -n "$real_influx" ] ; then
if [ -z "$INFLUX_TOKEN" ] && command -v bw >/dev/null ; then
export INFLUX_TOKEN="$(bw get password influx_token)"
fi
"$real_influx" "$@"
else
echo "influx not installed; not continuing"
fi
}
2022-08-06 05:16:17 +00:00
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
}
2022-08-07 02:46:26 +00:00
;;
2022-08-06 05:16:17 +00:00
esac
2024-05-11 00:07:23 +00:00