From eba4cbe76f75b70046f7775242e0b1433b5f7fb6 Mon Sep 17 00:00:00 2001 From: Carlos Marx Date: Wed, 18 Aug 2021 20:51:53 -0300 Subject: [PATCH] XDG-friendly config reload `prefix + R` is currently bound to sourcing `~/.tmux.conf`. For anyone using `~/.config/tmux/tmux.conf` or `${XDG_CONFIG_HOME}/tmux/tmux.conf`, this binding will be of no use, perhaps even misleading. This patch tests if the file `${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf` exists, if affirmative, it sources it, if not, it sources `~/.tmux.conf`. --- sensible.tmux | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sensible.tmux b/sensible.tmux index b3894cb..2eb96e2 100755 --- a/sensible.tmux +++ b/sensible.tmux @@ -64,6 +64,15 @@ key_binding_not_changed() { fi } +get_tmux_config() { + local tmux_config_xdg="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf" + local tmux_config="$HOME/.tmux.conf" + + [[ -f "${tmux_config_xdg}" ]] && tmux_config=${tmux_config_xdg} + + echo ${tmux_config} +} + main() { # OPTIONS @@ -147,9 +156,11 @@ main() { # source `.tmux.conf` file - as suggested in `man tmux` if key_binding_not_set "R"; then - tmux bind-key R run-shell ' \ - tmux source-file ~/.tmux.conf > /dev/null; \ - tmux display-message "Sourced .tmux.conf!"' + local tmux_config=$(get_tmux_config) + + tmux bind-key R run-shell " \ + tmux source-file ${tmux_config} > /dev/null; \ + tmux display-message 'Sourced ${tmux_config}!'" fi } main