-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for XDG Base Directory Specification #1282
Conversation
install
Outdated
@@ -9,6 +9,13 @@ update_config=2 | |||
binary_arch= | |||
allow_legacy= | |||
shells="bash zsh fish" | |||
config_dir=~/.config/fzf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't want to suddenly change the default directory after 4 and a half years. Please change it back to ~
.
(Also note that Travis CI build is failing because of the change.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted the default directory to ~/
, but also added a check to see if the user manually created a ~/.config/fzf
directory, which I hope is fine since some users want their dotfiles in ~/.confg
but don't want to set extra environment variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me.
install
Outdated
fish_dir=~/.config/fish | ||
if [[ -v XDG_CONFIG_HOME ]] && [ ! -z $XDG_CONFIG_HOME ] && [ -d $XDG_CONFIG_HOME ]; then | ||
config_dir=$XDG_CONFIG_HOME/fzf | ||
fish_dir=$XDG_CONFIG_HOME/fish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use 2-space indentation throughout the code.
uninstall
Outdated
fish_dir=~/.config/fish | ||
if [[ -v XDG_CONFIG_HOME ]] && [ ! -z $XDG_CONFIG_HOME ] && [ -d $XDG_CONFIG_HOME ]; then | ||
config_dir=$XDG_CONFIG_HOME/fzf | ||
fish_dir=$XDG_CONFIG_HOME/fish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation.
install
Outdated
@@ -9,6 +9,13 @@ update_config=2 | |||
binary_arch= | |||
allow_legacy= | |||
shells="bash zsh fish" | |||
config_dir=~/.config/fzf | |||
fish_dir=~/.config/fish | |||
if [[ -v XDG_CONFIG_HOME ]] && [ ! -z $XDG_CONFIG_HOME ] && [ -d $XDG_CONFIG_HOME ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-z
seems unnecessary. We can write [[ -v XDG_CONFIG_HOME ]] && [[ -d "$XDG_CONFIG_HOME" ]]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-z
does seems unnecessary, but the XDG base dir spec allows for that env var to be empty, in which case it should be ignored and code should use a default directory (normally ~/.config
).
From here
$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, thanks.
install
Outdated
@@ -9,6 +9,15 @@ update_config=2 | |||
binary_arch= | |||
allow_legacy= | |||
shells="bash zsh fish" | |||
config_base=~/. | |||
fish_dir=~/.config/fish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No slash at the end. Actually, I don't like requiring $fish_dir
to have a trailing slash, and I would much prefer $fish_dir/functions
over ${fish_dir}functions
as it's cleaner and less bug-prone. I can see that it's necessary for $config_base
, so we have either ~/.fzf.bash
or ~/.config/fzf/fzf.bash
but we don't have to do the same for $fish_dir
. Maybe we can rename $config_base
to $config_prefix
, to make the difference more explicit ("prefix" vs. "dir").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Thanks for the update, there's one more problem. Before the patch:
and after the patch
You see the difference? And I end up with both versions of the line in my [ -f ~/.fzf.bash ] && source ~/.fzf.bash
[ -f /Users/jg/.fzf.bash ] && source /Users/jg/.fzf.bash This is not desirable, and I have noticed that most users prefer the former as it can be used with different usernames. The following patch seems to fix the problem. Please let me know if you have a better idea. diff --git a/install b/install
index d131c82..ee851ad 100755
--- a/install
+++ b/install
@@ -9,14 +9,14 @@ update_config=2
binary_arch=
allow_legacy=
shells="bash zsh fish"
-config_prefix=~/.
+config_prefix="~/."
fish_dir=~/.config/fish
if [[ -v XDG_CONFIG_HOME ]] && [[ ! -z $XDG_CONFIG_HOME ]] && [[ -d $XDG_CONFIG_HOME ]]; then
config_prefix=$XDG_CONFIG_HOME/fzf/
fish_dir=$XDG_CONFIG_HOME/fish
mkdir -p $config_prefix
elif [[ -d ~/.config/fzf ]]; then
- config_prefix=~/.config/fzf/
+ config_prefix="~/.config/fzf/"
fi
help() {
@@ -262,7 +262,8 @@ for shell in $shells; do
fzf_key_bindings="# $fzf_key_bindings"
fi
- cat > $src << EOF
+ eval "src=\"$src\""
+ cat > "$src" << EOF
# Setup fzf
# ---------
if [[ ! "\$PATH" == *$fzf_base/bin* ]]; then |
Good point, thanks for the patch! |
Thanks, one more thing though, can you make the code compatible with the paths with whitespaces? We didn't have the problem before, but now we have to consider such unusual cases. export XDG_CONFIG_HOME="/tmp/foo bar"
mkdir -p "$XDG_CONFIG_HOME"
./install --all |
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
[ -f $XDG_CONFIG_HOME/fzf/fzf.bash ] && source $XDG_CONFIG_HOME/fzf/fzf.bash We can consider avoiding |
|
Thanks, but the space issue still lurks in a number of places. rm -f ~/.fzf.bash
export XDG_CONFIG_HOME="/tmp/foo bar"
mkdir -p "$XDG_CONFIG_HOME"
./install --all
|
Also note that export XDG_CONFIG_HOME="/tmp/foo bar"
mkdir -p "$XDG_CONFIG_HOME"
touch $XDG_CONFIG_HOME/baz
[ -f $XDG_CONFIG_HOME/baz ] && echo 1
# bash: [: /tmp/foo: binary operator expected |
[ -f "$XDG_CONFIG_HOME"/fzf/fzf.bash ] && source "$XDG_CONFIG_HOME"/fzf/fzf.bash
Sorry for the delay, I just pushed commits that should fix the whitespace issue. Tested with the following script: rm -f ~/.fzf.bash
export XDG_CONFIG_HOME="/tmp/foo bar"
mkdir -p "$XDG_CONFIG_HOME"
./install --all
./uninstall
unset XDG_CONFIG_HOME
rm -rf ~/.config/fzf
./install --all
./uninstall
mkdir -p ~/.config/fzf
./install --all
./uninstall Now, bashrc can have three versions of the line depending on the environment variables of the shell that runs the install script.
And I'm not sure if this is a good decision as it can be confusing. Maybe we should ditch the third case? |
Another option would be to combine the latter two: [ -f "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash ] && source "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash Doesn't look good though. |
The third case should be handled, and though its verbose I think your suggestion to do I'm adding a commit using that solution. It makes the xdg-compliant directory the default if |
The test script I posted above doesn't pass with the latest commit. |
To be precise, I'm seeing the following error messages during the process: Generate "${XDG_CONFIG_HOME:-~/.config}"/fzf/fzf.bash ... ./install: line 267: bar/fzf/fzf.bash: No such file or directory
OK
Generate "${XDG_CONFIG_HOME:-~/.config}"/fzf/fzf.zsh ... ./install: line 267: bar/fzf/fzf.zsh: No such file or directory
OK
Update fish_user_paths ... Failed |
Hmm, I'm thinking again if changing the default directory on fresh installation is a good call, because there are many users who have They will expect fzf installer to create the file on that particular path. How about we add |
install
Outdated
eval 'config_dir="$config_prefix"' | ||
eval "config_dir=$config_dir" | ||
eval "config_dir=$config_dir" | ||
echo $config_dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Echo for debugging?
uninstall
Outdated
eval 'config_dir="$config_prefix"' | ||
eval "config_dir=$config_dir" | ||
eval "config_dir=$config_dir" | ||
echo $config_dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
eval doesn't work well with XDG_CONFIG_HOME with whitespaces and it can be a security hole as bash will inadvertently execute any command injected in the variable. FOO="b ls" eval "a=$FOO" Also, replace tilde with $HOME to simplify the expansion.
Pushed a fix that removes Also I had to change mkdir -p ~/.config
unset XDG_CONFIG_HOME
[ -d "${XDG_CONFIG_HOME:-~/.config}" ] && echo found || echo not found
# not found
[ -d ${XDG_CONFIG_HOME:-~/.config} ] && echo found || echo not found
# found
[ -d "${XDG_CONFIG_HOME:-$HOME/.config}" ] && echo found || echo not found
# found Please review the change and let me know if there's anything else you want to address. I'll merge this if everything's okay. |
That looks good. Works for me |
Merged, thanks! |
Hi, I am still new to this XDG Base Directory thing. Just curious, why is the fzf installed into the |
Here another newbie. I have set XDG_CONFIG_HOME to .config , and created, .config/fzf. Should it store dotfiles there without setting any env var? I have to reinstall fzf? |
Another newbie here with the same wonder. Has someone come up to solve it eventually? Edit: never mind, just found it here:
|
@junegunn any chance we can have the I could help with making this change. |
This makes it possible to keep your home directory free from fzf dotfiles. One thing to note is that this does not handle the case where a ~/.fzf.bash file already exists. I can include that if desired.