initial commit
This commit is contained in:
+149
@@ -0,0 +1,149 @@
|
||||
# mkshrc notes
|
||||
|
||||
Checked `mkshrc` with:
|
||||
|
||||
```sh
|
||||
mksh -n mkshrc
|
||||
```
|
||||
|
||||
Syntax check passes, but these issues/suspicious spots were found.
|
||||
|
||||
## Issues
|
||||
|
||||
1. **Mason PATH bug**
|
||||
|
||||
```sh
|
||||
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:
|
||||
|
||||
```sh
|
||||
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:
|
||||
|
||||
```text
|
||||
stty: standard input: Not a tty
|
||||
mksh: ./mkshrc[12]: bind: can't bind, not a tty
|
||||
```
|
||||
|
||||
Suggested guard:
|
||||
|
||||
```sh
|
||||
[[ -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**
|
||||
|
||||
```sh
|
||||
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**
|
||||
|
||||
```sh
|
||||
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 `~`**
|
||||
|
||||
```sh
|
||||
export W3M_DIR="~/.cache/w3m"
|
||||
```
|
||||
|
||||
Because `~` is quoted, it will not expand.
|
||||
|
||||
Suggested fix:
|
||||
|
||||
```sh
|
||||
export W3M_DIR="$HOME/.cache/w3m"
|
||||
```
|
||||
|
||||
6. **`dkr()` has a bug with multiple args**
|
||||
|
||||
```sh
|
||||
[ -z "$@" ] && cmd="echo"
|
||||
```
|
||||
|
||||
With multiple arguments this can error in mksh. Use:
|
||||
|
||||
```sh
|
||||
(( $# == 0 )) && cmd="echo"
|
||||
```
|
||||
|
||||
Also:
|
||||
|
||||
```sh
|
||||
cmd="docker $@"
|
||||
```
|
||||
|
||||
loses argument quoting and can behave badly with spaces/shell metacharacters.
|
||||
|
||||
7. **`loop()` should quote args**
|
||||
|
||||
Current:
|
||||
|
||||
```sh
|
||||
loop() { while true ; do $@; sleep 1; done ;}
|
||||
```
|
||||
|
||||
Safer:
|
||||
|
||||
```sh
|
||||
loop() { while true; do "$@"; sleep 1; done; }
|
||||
```
|
||||
|
||||
8. **ANSI gray fallback is probably wrong**
|
||||
|
||||
```sh
|
||||
txtgry="$(tput setaf 8 2>/dev/null || echo '\e[0;38m')"
|
||||
```
|
||||
|
||||
`38` normally expects extended color parameters. Better fallback:
|
||||
|
||||
```sh
|
||||
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:
|
||||
|
||||
```sh
|
||||
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.
|
||||
Reference in New Issue
Block a user