3.0 KiB
mkshrc notes
Checked mkshrc with:
mksh -n mkshrc
Syntax check passes, but these issues/suspicious spots were found.
Issues
-
Mason PATH bug
test -d $HOME/.local/share/nvim/mason/bin && export PATH=$HOME/.local/share/mason/bin:$PATHThe test checks
~/.local/share/nvim/mason/bin, but the exported path is~/.local/share/mason/bin. On this machine the checked directory exists and the exported directory does not.Suggested fix:
test -d "$HOME/.local/share/nvim/mason/bin" && export PATH="$HOME/.local/share/nvim/mason/bin:$PATH" -
stty/bindemit errors without a ttyNon-interactive sourcing produced errors like:
stty: standard input: Not a tty mksh: ./mkshrc[12]: bind: can't bind, not a ttySuggested guard:
[[ -t 0 ]] && stty -ixon [[ -o interactive ]] && { bind '^l'=clear-screen bind '^k'=kill-line bind '^j'=kill-to-eol bind '^e'=edit-line } -
HISTFILESIZEandHISTCONTROLare bash-styleexport HISTFILESIZE=10000 export HISTCONTROL=ignoredupsThese are likely ignored by mksh. mksh generally uses
HISTSIZE/HISTFILE;HISTCONTROL=ignoredupsis not a mksh feature. -
LESSHISTFILEis set multiple timesexport SHELL=$MKSH MANWIDTH=80 LESSHISTFILE=- export LESSHISTFILE=$HOME/.cache/lesshist export LESSHISTFILE="$XDG_STATE_HOME"/less/historyFinal value wins. Also
~/.local/state/lessdoes not currently exist, so less may fail to write history unless created. -
W3M_DIRcontains literal~export W3M_DIR="~/.cache/w3m"Because
~is quoted, it will not expand.Suggested fix:
export W3M_DIR="$HOME/.cache/w3m" -
dkr()has a bug with multiple args[ -z "$@" ] && cmd="echo"With multiple arguments this can error in mksh. Use:
(( $# == 0 )) && cmd="echo"Also:
cmd="docker $@"loses argument quoting and can behave badly with spaces/shell metacharacters.
-
loop()should quote argsCurrent:
loop() { while true ; do $@; sleep 1; done ;}Safer:
loop() { while true; do "$@"; sleep 1; done; } -
ANSI gray fallback is probably wrong
txtgry="$(tput setaf 8 2>/dev/null || echo '\e[0;38m')"38normally expects extended color parameters. Better fallback:echo '\e[0;90m' -
PATH grows on repeated sourcing
Re-sourcing this file repeatedly prepends/appends duplicate PATH entries. Not fatal, but noticeable.
-
Dangerous aliases
These may be intentional, but are worth noting:
alias cp='cp -r' alias rm='rm -r' alias docker='doas docker'rm -rby default can make accidents worse.
Most important fixes
- Fix Mason path line.
- Fix
W3M_DIR. - Fix
dkr()argument check/quoting. - Guard
stty/bindfor non-tty/non-interactive use.