fish: write function to enable `open -a appname[.desktop]` on linux
Alan Pearce alan@alanpearce.eu
Sun, 28 Apr 2024 15:07:41 +0200
1 files changed, 18 insertions(+), 1 deletions(-)
jump to
M user/settings/fish.nix → user/settings/fish.nix
@@ -43,7 +43,24 @@ }; functions = { ds = "du -hd1 $argv[1] | sort -h"; last_history_item = "echo $history[1]"; - }; + } // (lib.attrsets.optionalAttrs pkgs.stdenv.isLinux { + open = '' + argparse h/help a/application -- $argv + or return + + if set -ql _flag_help + echo "open [-h|--help] [-a application] [arguments...]" + return 1 + end + + if set -ql _flag_application + # TODO: support reverse-domain- named files (e.g. org.kde.kate.desktop) + ${pkgs.gtk3}/bin/gtk-launch $argv[1] + else + xdg-open $argv + end + ''; + }); }; xdg.configFile."fish/completions" = { recursive = true;