From 1b2a5d1fc7e2097d239c297962f9bc70ab8e78b4 Mon Sep 17 00:00:00 2001 From: Christopher Aubut Date: Wed, 10 Jan 2024 19:52:15 -0700 Subject: [PATCH] feat(xdg): adds additional pathing options --- README.md | 22 ++++++++++++++++------ plugin.sh.tmux | 26 +++++++++++++++++++++----- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 815e235..b64ea5b 100644 --- a/README.md +++ b/README.md @@ -255,11 +255,21 @@ set -g @plugin 'alexwforsythe/tmux-which-key' ##### @tmux-which-key-enable-xdg-dirs -Moves the configuration file to -`$XDG_CONFIG_HOME/tmux-plugins/tmux-which-key/config.yaml` +Enables the use of XDG directories for the configuration and init files. + +With this option enabled, the following option also becomes available: + +```tmux +# relative path from $XDG_*_HOME for files +set -g @tmux-which-key-xdg-plugin-path=tmux/plugins/tmux-which-key # default +``` + +Enabling moves the configuration file to +`$XDG_CONFIG_HOME/<@tmux-which-key-xdg-plugin-path>/config.yaml` and the init file to -`$XDG_DATA_HOME/tmux-plugins/tmux-which-key/init.tmux`. -Allows the plugin to be used with immutable or declarative operating systems. +`$XDG_DATA_HOME/<@tmux-which-key-xdg-plugin-path>/init.tmux`. +The allows the plugin to also be used with immutable or declarative operating +systems. ```tmux set -g @tmux-which-key-enable-xdg-dirs=1 @@ -281,7 +291,7 @@ set -g @plugin 'alexwforsythe/tmux-which-key' pkgs.tmuxPlugins.mkTmuxPlugin { pluginName = "tmux-which-key"; - version = ""; + version = "2024-01-10"; src = pkgs.fetchFromGitHub { owner = "alexwforsythe"; repo = "tmux-which-key"; @@ -292,7 +302,7 @@ set -g @plugin 'alexwforsythe/tmux-which-key' }; in { xdg.configFile = { - "tmux-plugins/tmux-which-key/config.yaml".text = lib.generators.toYAML {} { + "tmux/plugins/tmux-which-key/config.yaml".text = lib.generators.toYAML {} { command_alias_start_index = 200; # rest of config here }; diff --git a/plugin.sh.tmux b/plugin.sh.tmux index b183a02..b6d9e2a 100755 --- a/plugin.sh.tmux +++ b/plugin.sh.tmux @@ -17,11 +17,27 @@ init_file="$plugin_dir/init.tmux" # XDG case "$(tmux show-option -gvq @tmux-which-key-enable-xdg-dirs)" in 1 | true) - # do not create base XDG dirs if they don't exist - (cd "$XDG_CONFIG_HOME" && mkdir -p tmux-plugins/tmux-which-key) - (cd "$XDG_DATA_HOME" && mkdir -p tmux-plugins/tmux-which-key) - config_file="$XDG_CONFIG_HOME/tmux-plugins/tmux-which-key/config.yaml" - init_file="$XDG_DATA_HOME/tmux-plugins/tmux-which-key/init.tmux" + if [ -z "$XDG_CONFIG_HOME" ]; then + echo "[tmux-which-key] XDG_CONFIG_HOME is not set" + exit 1 + fi + if [ ! -d "$XDG_CONFIG_HOME" ]; then + echo "[tmux-which-key] XDG_CONFIG_HOME: $XDG_CONFIG_HOME does not exist" + fi + if [ -z "$XDG_DATA_HOME" ]; then + echo "[tmux-which-key] XDG_DATA_HOME is not set" + exit 1 + fi + if [ ! -d "$XDG_DATA_HOME" ]; then + echo "[tmux-which-key] XDG_CONFIG_HOME: $XDG_DATA_HOME does not exist" + exit 1 + fi + xdg_plugin_path=$(tmux show-option -gvq @tmux-which-key-xdg-plugin-path) + xdg_plugin_path=${xdg_plugin_path:-tmux/plugins/tmux-which-key} + mkdir -p "$XDG_CONFIG_HOME/$xdg_plugin_path" + mkdir -p "$XDG_DATA_HOME/$xdg_plugin_path" + config_file="$XDG_CONFIG_HOME/$xdg_plugin_path/config.yaml" + init_file="$XDG_DATA_HOME/$xdg_plugin_path/init.tmux" ;; esac