Skip to content

Commit

Permalink
feat(xdg): adds additional pathing options
Browse files Browse the repository at this point in the history
  • Loading branch information
higherorderfunctor committed Jan 11, 2024
1 parent ed7bba2 commit 1b2a5d1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -281,7 +291,7 @@ set -g @plugin 'alexwforsythe/tmux-which-key'
pkgs.tmuxPlugins.mkTmuxPlugin
{
pluginName = "tmux-which-key";
version = "<short commit hash>";
version = "2024-01-10";
src = pkgs.fetchFromGitHub {
owner = "alexwforsythe";
repo = "tmux-which-key";
Expand All @@ -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
};
Expand Down
26 changes: 21 additions & 5 deletions plugin.sh.tmux
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1b2a5d1

Please sign in to comment.