overcast07 / wayback-machine-spn-scripts

Bash scripts which interact with Internet Archive Wayback Machine's Save Page Now
MIT License
104 stars 9 forks source link

Set default data directory according to XDG directory specs and add archlinux installation instructions #22

Closed otuva closed 1 year ago

otuva commented 1 year ago

The script in this current version will try to put data under ~/spn-data by default With this change, however, it will try to read XDG_DATA_HOME variable and if it cannot find the variable will default to $HOME/.local/share/

overcast07 commented 1 year ago

I primarily run this script on macOS, which doesn't support the XDG_DATA_HOME variable. I would prefer for the current default of $HOME/spn-data to be retained, in order to make the folder easier to find, rather than putting it in a hidden folder.

This change would make the script unusable by default on macOS, since the parent folder needs to exist before mkdir can create the new folder. Currently, I get the error mkdir: /Users/user\/.local\/share: No such file or directory. The backslashes appear to be unnecessary, but I don't know if this is OS-specific behavior. I'm also not sure if the $HOME/local/share folder exists on every Unix system or if it needs to be created in some cases.

otuva commented 1 year ago

This should fix it, I didn't think about macOS on the first commit :)

in order to make the folder easier to find, rather than putting it in a hidden folder.

I don't think findability matters that much here, it's about not polluting the user space, which follows Apple's guidelines

And under macOS it still is pretty findable, I think. Just 2 directories

Current directory location is not just aesthetics either, it will cause problems to anyone using industry-standard backup practices

https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFileSystem/Articles/WhereToPutFiles.html

The backslashes appear to be unnecessary

The default value used in case variable doesn't exist read raw and any special characters need to be escaped. Because it's a path anyway, probably wouldn't matter too much. If you want, you can delete it but here's what it looks like

parent="${XDG_DATA_HOME:-$HOME\/.local\/share}/spn-data"
echo $parent 
/home/tfp/.local/share/spn-data

on every Unix system or if it needs to be created in some cases

If it's a modern system (after 2000s) 99.9999% it will exist.

https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

otuva commented 1 year ago

Anyway, as per your request I've made those modifications too, looking forward for your feedback :)

overcast07 commented 1 year ago

Bash on macOS doesn't seem to ignore the backslashes. The below behavior occurs for me.

parent="${XDG_DATA_HOME:-$HOME\/.local\/share}/spn-data"; echo $parent
/Users/user\/.local\/share/spn-data
parent="${XDG_DATA_HOME:-$HOME/.local/share}/spn-data"; echo $parent 
/Users/user/.local/share/spn-data
overcast07 commented 1 year ago

I'll merge the pull request once I'm done reviewing the code and testing on my own computer.