LucasLarson/dotfiles

hardcoded references to `edit` will break

LucasLarson opened this issue · 0 comments

edit is not at all portable here:

alias aliases='edit ${ZSH:-${HOME}/.oh-my-${SHELL##*/}}/custom/aliases.${SHELL##*/}; . ${HOME}/.${SHELL##*/}rc && exec ${SHELL##*/} --login'
alias ohmyzsh='cd ${ZSH:-${HOME}/.oh-my-${SHELL##*/}}'
alias zshconfig='edit ${HOME}/.${SHELL##*/}rc; . ${HOME}/.${SHELL##*/}rc && exec ${SHELL##*/} --login'
alias zshenv='edit ${HOME}/.${SHELL##*/}env; . ${HOME}/.${SHELL##*/}rc && exec ${SHELL##*/} --login'

A solution like ${EDITOR:-vi}¹ instead of edit² is portable and should replace it.


  1. this may not be the correct if-not-𝑥-then-𝑦 syntax when calling a binary like /usr/bin/vi, but it’s close
  2. edit is defined as:

    dotfiles/.zshenv

    Lines 8 to 20 in 9c37ff8

    if command -v nvim > /dev/null 2>&1; then
    EDITOR="nvim"
    elif command -v vim > /dev/null 2>&1; then
    EDITOR="vim"
    elif command -v vi > /dev/null 2>&1; then
    EDITOR="vi"
    else
    EDITOR="nano"
    fi
    export EDITOR
    # https://github.com/koalaman/shellcheck/wiki/SC2139/db553bf16fcb86b2cdc77b835e75b9121eacc429#this-expands-when-defined-not-when-used-consider-escaping
    alias editor='$EDITOR'
    alias edit="editor"