{
  writeShellApplication,
  fd,
  fzf,
}:
writeShellApplication {
  name = "edit-config";

  runtimeInputs = [
    fd
    fzf
  ];

  text = ''
    if [[ $# == 0 ]]; then
       QUERY=""
    else
       QUERY="$1"
    fi

    FILE=$(fd -H -t f . ~/.dotfiles | fzf --query "$QUERY")
    if [[ "$FILE" != "" ]]; then
      $EDITOR "$FILE"
    else
      exit 1
    fi

    read -rp 'Run "home-manager switch"? [Yn]: ' yn
    case $yn in
        Y | y | Yes | yes | "" ) home-manager switch;;
        * ) echo "Not switching home-manager configuration";;
    esac
  '';
}