From a186f04f15773b4595d0e359d1e27a903a68d3f7 Mon Sep 17 00:00:00 2001 From: David Adam Date: Mon, 29 Sep 2014 19:39:36 +0800 Subject: [PATCH] Manpage completions: store in $XDG_DATA_HOME Closes #1343, works towards #1257. --- share/config.fish | 8 +++++++- share/functions/__fish_config_interactive.fish | 7 ++++++- share/functions/fish_update_completions.fish | 3 ++- share/tools/create_manpage_completions.py | 3 ++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/share/config.fish b/share/config.fish index 94046a6c5..b681d189a 100644 --- a/share/config.fish +++ b/share/config.fish @@ -36,6 +36,12 @@ if set -q XDG_CONFIG_HOME set configdir $XDG_CONFIG_HOME end +set -l userdatadir ~/.local/share + +if set -q XDG_DATA_HOME + set userdatadir $XDG_DATA_HOME +end + # __fish_datadir, __fish_sysconfdir, __fish_help_dir, __fish_bin_dir # are expected to have been set up by read_init from fish.cpp @@ -51,7 +57,7 @@ if not contains $__fish_datadir/functions $fish_function_path end if not set -q fish_complete_path - set fish_complete_path $configdir/fish/completions $__fish_sysconfdir/completions $__fish_datadir/completions $configdir/fish/generated_completions + set fish_complete_path $configdir/fish/completions $__fish_sysconfdir/completions $__fish_datadir/completions $userdatadir/fish/generated_completions end if not contains $__fish_datadir/completions $fish_complete_path diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index 45b2e710b..f98a9e6f3 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -19,6 +19,11 @@ function __fish_config_interactive -d "Initializations that should be performed if set -q XDG_CONFIG_HOME set configdir $XDG_CONFIG_HOME end + # Set the correct user data directory + set -l userdatadir ~/.local/share + if set -q XDG_DATA_HOME + set userdatadir $XDG_DATA_HOME + end # Migrate old (pre 1.22.0) init scripts if they exist if not set -q __fish_init_1_22_0 @@ -144,7 +149,7 @@ function __fish_config_interactive -d "Initializations that should be performed # Generate man page completions if not present # - if not test -d $configdir/fish/generated_completions + if not test -d $userdatadir/fish/generated_completions #fish_update_completions is a function, so it can not be directly run in background. eval "$__fish_bin_dir/fish -c 'fish_update_completions > /dev/null ^/dev/null' &" end diff --git a/share/functions/fish_update_completions.fish b/share/functions/fish_update_completions.fish index 714ae6ef5..2a65441d3 100644 --- a/share/functions/fish_update_completions.fish +++ b/share/functions/fish_update_completions.fish @@ -1,3 +1,4 @@ function fish_update_completions --description "Update man-page based completions" - eval \"$__fish_datadir/tools/create_manpage_completions.py\" --manpath --progress --cleanup-in '~/.config/fish/completions' + # Clean up old paths + eval \"$__fish_datadir/tools/create_manpage_completions.py\" --manpath --progress --cleanup-in '~/.config/fish/completions' --cleanup-in '~/.config/fish/generated_completions' end diff --git a/share/tools/create_manpage_completions.py b/share/tools/create_manpage_completions.py index 7b1879dd0..376156ae8 100755 --- a/share/tools/create_manpage_completions.py +++ b/share/tools/create_manpage_completions.py @@ -973,7 +973,8 @@ if __name__ == "__main__": if not WRITE_TO_STDOUT and not output_directory: # Default to ~/.config/fish/generated_completions/ # Create it if it doesn't exist - output_directory = os.path.expanduser('~/.config/fish/generated_completions/') + xdg_data_home = os.getenv('XDG_DATA_HOME', '~/.local/share') + output_directory = os.path.expanduser(xdg_data_home + '/fish/generated_completions/') try: os.makedirs(output_directory) except OSError as e: