Files
daniel fusser beeefb13a7 initial commit
2026-06-21 15:35:58 +02:00

3.0 KiB

mkshrc notes

Checked mkshrc with:

mksh -n mkshrc

Syntax check passes, but these issues/suspicious spots were found.

Issues

  1. Mason PATH bug

    test -d $HOME/.local/share/nvim/mason/bin && export PATH=$HOME/.local/share/mason/bin:$PATH
    

    The 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"
    
  2. stty / bind emit errors without a tty

    Non-interactive sourcing produced errors like:

    stty: standard input: Not a tty
    mksh: ./mkshrc[12]: bind: can't bind, not a tty
    

    Suggested guard:

    [[ -t 0 ]] && stty -ixon
    [[ -o interactive ]] && {
      bind '^l'=clear-screen
      bind '^k'=kill-line
      bind '^j'=kill-to-eol
      bind '^e'=edit-line
    }
    
  3. HISTFILESIZE and HISTCONTROL are bash-style

    export HISTFILESIZE=10000
    export HISTCONTROL=ignoredups
    

    These are likely ignored by mksh. mksh generally uses HISTSIZE/HISTFILE; HISTCONTROL=ignoredups is not a mksh feature.

  4. LESSHISTFILE is set multiple times

    export SHELL=$MKSH MANWIDTH=80 LESSHISTFILE=-
    export LESSHISTFILE=$HOME/.cache/lesshist
    export LESSHISTFILE="$XDG_STATE_HOME"/less/history
    

    Final value wins. Also ~/.local/state/less does not currently exist, so less may fail to write history unless created.

  5. W3M_DIR contains literal ~

    export W3M_DIR="~/.cache/w3m"
    

    Because ~ is quoted, it will not expand.

    Suggested fix:

    export W3M_DIR="$HOME/.cache/w3m"
    
  6. 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.

  7. loop() should quote args

    Current:

    loop() { while true ; do $@; sleep 1; done ;}
    

    Safer:

    loop() { while true; do "$@"; sleep 1; done; }
    
  8. ANSI gray fallback is probably wrong

    txtgry="$(tput setaf 8 2>/dev/null || echo '\e[0;38m')"
    

    38 normally expects extended color parameters. Better fallback:

    echo '\e[0;90m'
    
  9. PATH grows on repeated sourcing

    Re-sourcing this file repeatedly prepends/appends duplicate PATH entries. Not fatal, but noticeable.

  10. Dangerous aliases

    These may be intentional, but are worth noting:

    alias cp='cp -r'
    alias rm='rm -r'
    alias docker='doas docker'
    

    rm -r by default can make accidents worse.

Most important fixes

  • Fix Mason path line.
  • Fix W3M_DIR.
  • Fix dkr() argument check/quoting.
  • Guard stty/bind for non-tty/non-interactive use.