From: b3nj5m1n <47924309+b3nj5m1n@users.noreply.github.com> Date: Thu, 28 Sep 2023 12:26:34 +0000 (+0200) Subject: Merge pull request #264 from Midblyte/main X-Git-Tag: v0.2.0.2~25 X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/xdg-ninja.git/commitdiff_plain/47a833ae2a48072598802ad017d2113c2cd9e65d?hp=5c14da9256501b4a58d9ac75e290d31a5cb79cfb Merge pull request #264 from Midblyte/main --- diff --git a/README.md b/README.md index 4e13201..9af8c77 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A shell script which checks your _$HOME_ for unwanted files and directories.

- +

When it encounters a file it knows about, it will tell you whether it's possible to move this file to an appropriate location, and how to do it. @@ -36,6 +36,7 @@ To install xdg-ninja with [Homebrew](https://brew.sh), run `brew install xdg-nin - your favorite POSIX-compliant shell ([bash](https://repology.org/project/bash/packages), [zsh](https://repology.org/project/zsh/packages), [dash](https://repology.org/project/dash-shell/packages), ...) - [jq](https://repology.org/project/jq/packages) for parsing the json files +- [find](https://repology.org/project/findutils/versions) ### Optional diff --git a/flake.nix b/flake.nix index 8f3a5bf..5a1be2c 100644 --- a/flake.nix +++ b/flake.nix @@ -13,6 +13,7 @@ runtimeDependencies = with pkgs; [ glow jq + findutils ]; overlays = [ (self: super: { diff --git a/programs/R.json b/programs/R.json new file mode 100644 index 0000000..4fdf768 --- /dev/null +++ b/programs/R.json @@ -0,0 +1,10 @@ +{ + "name": "R", + "files": [ + { + "path": "$HOME/R", + "movable": true, + "help": "Set R_LIBS_USER in `$HOME/.Renviron:\n\n```\nR_LIBS_USER=\"$XDG_DATA_HOME\"/R/x86_64-pc-linux-gnu-library\n```\n\nYou may find it necessary to append this line to the end of `/usr/lib/R/library/base/R/Rprofile`:\n\n```R.libPaths( c( \"$XDG_DATA_HOME/R/x86_64-pc-linux-gnu-library/\" , .libPaths() ) )```\n\n**Disclaimer: You may need to re-install your libraries**" + } + ] +} diff --git a/programs/android-studio.json b/programs/android-studio.json deleted file mode 100644 index ce08850..0000000 --- a/programs/android-studio.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "files": [ - { - "help": "Try exporting the following environment variables:\n\n```bash\nexport ANDROID_HOME=\"$XDG_DATA_HOME\"/android\n```\n\n**adb** will always generate \"$HOME/.android/adbkeys\".\n", - "movable": false, - "path": "$HOME/.android" - } - ], - "name": "android-studio" -} \ No newline at end of file diff --git a/programs/android.json b/programs/android.json new file mode 100644 index 0000000..4d3273e --- /dev/null +++ b/programs/android.json @@ -0,0 +1,10 @@ +{ + "files": [ + { + "help": "Export the following environment variable:\n\n```bash\nexport ANDROID_HOME=\"$XDG_DATA_HOME\"/android\n```\n\nAdditionally, if you use adb, use the following alias:\n\n```bash\nalias adb='HOME=\"$XDG_DATA_HOME\"/android adb'\n```\n\n", + "movable": true, + "path": "$HOME/.android" + } + ], + "name": "android" +} diff --git a/programs/ansible.json b/programs/ansible.json index 076a76a..dba6da9 100644 --- a/programs/ansible.json +++ b/programs/ansible.json @@ -2,8 +2,8 @@ "files": [ { "path": "$HOME/.ansible", - "movable": false, - "help": "See [this](https://github.com/ansible/ansible/commit/d7fbde4ea9db6cc44e81c39d699595330f4fa3c6) pull request.\n\nSeems to be implemented now, you should be able to set the _ANSIBLE_HOME_ environment variable.\n\nI couldn't get it to work yet unfortunately, and you might need to wait for a new release.\n" + "movable": true, + "help": "Export the following environment variables:\n\n```bash\nexport ANSIBLE_HOME=\"$XDG_DATA_HOME\"/ansible\n```\n" } ], "name": "ansible" diff --git a/programs/antigen.json b/programs/antigen.json new file mode 100644 index 0000000..736a3c1 --- /dev/null +++ b/programs/antigen.json @@ -0,0 +1,10 @@ +{ + "files": [ + { + "path": "$HOME/.antigen", + "movable": true, + "help": "Export the following environmental variable:\n\n```bash\nexport ADOTDIR=\"$XDG_DATA_HOME\"/antigen\n```\n\n_Note: do_ **not** _move the pre-existing antigen folder from $HOME/.antigen to the new location because it would make antigen crash (the reason is antigen hardcodes the \"$HOME/.antigen\" directory in the `init.zsh` file upon installation of the bundle), simply_ **remove** _\"$HOME/.antigen\" and the next time you will spawn an instance of zsh, antigen will install all the plugins correctly in the new location (and hardcode the new, correct, location)._\n" + } + ], + "name": "antigen" +} diff --git a/programs/aria2.json b/programs/aria2.json index 1cb2248..998873c 100644 --- a/programs/aria2.json +++ b/programs/aria2.json @@ -7,9 +7,9 @@ "help": "Supported\n\nThe file $HOME/.aria2/dht.dat can be moved to $XDG_CACHE_HOME/aria2/dht.dat.\n" }, { - "path": "$HOME/.aria2/aria.conf", + "path": "$HOME/.aria2/aria2.conf", "movable": true, - "help": "Supported\n\nThe file $HOME/.aria2/aria.conf can be moved to $XDG_CONFIG_HOME/aria2/aria2.conf.\n" + "help": "Supported\n\nThe file $HOME/.aria2/aria2.conf can be moved to $XDG_CONFIG_HOME/aria2/aria2.conf.\n" } ] } diff --git a/programs/cups.json b/programs/cups.json index 5620087..c947d24 100644 --- a/programs/cups.json +++ b/programs/cups.json @@ -1,10 +1,10 @@ { - "name": "CUPS", - "files": [ - { - "path": "$HOME/.cups", - "movable": false, - "help": "Currently unsupported.\n\n_Relevant issue:_ https://github.com/OpenPrinting/cups/issues/10\n" - } - ] + "name": "CUPS", + "files": [ + { + "path": "$HOME/.cups", + "movable": true, + "help": "Supported.\n\nThe file $HOME/.cups can be moved to $XDG_CONFIG_HOME/cups.\n\n_Relevant issue:_ https://github.com/OpenPrinting/cups/issues/10\n" + } + ] } diff --git a/programs/davfs2.json b/programs/davfs2.json new file mode 100644 index 0000000..16687f6 --- /dev/null +++ b/programs/davfs2.json @@ -0,0 +1,10 @@ +{ + "name": "davfs2", + "files": [ + { + "path": "$HOME/.davfs2", + "movable": false, + "help": "Currently unsupported.\n\n_Relevant issue:_ https://savannah.nongnu.org/support/?110249\n" + } + ] +} diff --git a/programs/easyocr b/programs/easyocr new file mode 100644 index 0000000..e1cbebb --- /dev/null +++ b/programs/easyocr @@ -0,0 +1,10 @@ +{ + "name": "easyocr", + "files": [ + { + "path": "$HOME/.EasyOCR", + "movable": true, + "help": "Export the following environment variable:\n\n```bash\nexport EASYOCR_MODULE_PATH=\"$XDG_CONFIG_HOME/EasyOCR\"\n```\n" + } + ] +} diff --git a/programs/fennel.json b/programs/fennel.json new file mode 100644 index 0000000..01a0ee4 --- /dev/null +++ b/programs/fennel.json @@ -0,0 +1,10 @@ +{ + "name": "fennel", + "files": [ + { + "path": "$HOME/.fennelrc", + "movable": true, + "help": "Supported since _v0.3.1_.\n\nYou can move the file to _$XDG_CONFIG_HOME/fennel/fennelrc_.\n" + } + ] +} diff --git a/programs/gdb.json b/programs/gdb.json index 0f066a8..d9121d2 100644 --- a/programs/gdb.json +++ b/programs/gdb.json @@ -4,7 +4,7 @@ { "path": "$HOME/.gdbinit", "movable": true, - "help": "Alias gdb to use custom locations:\n\n```bash\nalias gdb=gdb -n -x $XDG_CONFIG_HOME/gdb/init```\n" + "help": "XDG is supported out-of-the-box, so you can simply move the file to _$XDG_CONFIG_HOME/gdb/gdbinit_.\n" }, { "path": "$HOME/.gdb_history", diff --git a/programs/gore.json b/programs/gore.json new file mode 100644 index 0000000..749bc29 --- /dev/null +++ b/programs/gore.json @@ -0,0 +1,10 @@ +{ + "files": [ + { + "path": "$HOME/.gore", + "movable": true, + "help": "Export the following environment variables:\n\n```bash\nexport GORE_HOME=\"$XDG_DATA_HOME/gore\"\n```\n" + } + ], + "name": "gore" +} \ No newline at end of file diff --git a/programs/guile.json b/programs/guile.json new file mode 100644 index 0000000..80bdad3 --- /dev/null +++ b/programs/guile.json @@ -0,0 +1,10 @@ +{ + "files": [ + { + "path": "$HOME/.guile_history", + "movable": true, + "help": "Export the following environment variable:\n\n```bash\nexport GUILE_HISTORY=\"$XDG_STATE_HOME\"/guile_history\n```\n" + } + ], + "name": "guile" +} diff --git a/programs/influx-cli.json b/programs/influx-cli.json new file mode 100644 index 0000000..d76f312 --- /dev/null +++ b/programs/influx-cli.json @@ -0,0 +1,11 @@ + +{ + "name": "influx-cli", + "files": [ + { + "path": "$HOME/.influx_history", + "movable": false, + "help": "Currently unsupported\n\n _Relevant issue:_ https://github.com/influxdata/influx-cli/issues/514" + } + ] +} diff --git a/programs/john.json b/programs/john.json new file mode 100644 index 0000000..5e3e1e5 --- /dev/null +++ b/programs/john.json @@ -0,0 +1,10 @@ +{ + "name": "john", + "files": [ + { + "path": "$HOME/.john", + "movable": false, + "help": "Currently unsupported.\n\n_Relevant issue:_ https://github.com/openwall/john/issues/4552\n" + } + ] +} diff --git a/programs/minetest.json b/programs/minetest.json new file mode 100644 index 0000000..72c794f --- /dev/null +++ b/programs/minetest.json @@ -0,0 +1,10 @@ +{ + "name": "minetest", + "files": [ + { + "path": "$HOME/.minetest", + "movable": true, + "help": "Export the following environment variables:\n\n```bash\nexport MINETEST_USER_PATH=\"$XDG_DATA_HOME\"/minetest\n```\n" + } + ] +} diff --git a/programs/openjdk.json b/programs/openjdk.json index b40319c..2a031d0 100644 --- a/programs/openjdk.json +++ b/programs/openjdk.json @@ -3,7 +3,7 @@ { "path": "$HOME/.java", "movable": false, - "help": "**Disclaimer: some applications don't respect this setting.**\n\nExport the following environment variable:\n\n```bash\nexport _JAVA_OPTIONS=-Djava.util.prefs.userRoot=\"$XDG_CONFIG_HOME\"/java\n```\n\nSee [ticket](https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8290140)" + "help": "**Disclaimer: some applications don't respect this setting.**\n\nExport the following environment variable:\n\n```bash\nexport _JAVA_OPTIONS=-Djava.util.prefs.userRoot=\"$XDG_CONFIG_HOME\"/java\n```\n\nSee [ticket](https://bugs.java.com/bugdatabase/view_bug?bug_id=8290140)" } ], "name": "openjdk" diff --git a/programs/pciutils.json b/programs/pciutils.json new file mode 100644 index 0000000..bcd8957 --- /dev/null +++ b/programs/pciutils.json @@ -0,0 +1,10 @@ +{ + "name": "pciutils", + "files": [ + { + "path": "$HOME/.pciids-cache", + "movable": false, + "help": "Currently unsupported.\n\n_Relevant issue:_ https://github.com/pciutils/pciutils/issues/148\n" + } + ] +} diff --git a/programs/pinfo.json b/programs/pinfo.json new file mode 100644 index 0000000..ff2eb2c --- /dev/null +++ b/programs/pinfo.json @@ -0,0 +1,10 @@ +{ + "files": [ + { + "help": "Move .pinforc to $XDG_CONFIG_HOME/pinfo/pinforc\nand set this alias in your shell\n\nalias pinfo='pinfo --rcfile=$HOME/.config/pinfo/pinforc'\n", + "movable": true, + "path": "$HOME/.pinforc" + } + ], + "name": "pinfo" +} diff --git a/programs/psensor.json b/programs/psensor.json new file mode 100644 index 0000000..03cbdc2 --- /dev/null +++ b/programs/psensor.json @@ -0,0 +1,10 @@ +{ + "name": "psensor", + "files": [ + { + "path": "$HOME/.psensor", + "movable": false, + "help": "Currently unsupported.\n\n_Relevant patch:_ https://gitlab.com/jeanfi/psensor/-/merge_requests/27\n" + } + ] +} diff --git a/programs/rstudio.json b/programs/rstudio.json deleted file mode 100644 index 3b96acf..0000000 --- a/programs/rstudio.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "rstudio", - "files": [ - { - "path": "$HOME/R", - "movable": true, - "help": "Default directory location can be configured in RStudio\nReference: https://www.accelebrate.com/library/how-to-articles/r-rstudio-library" - } - ] -} diff --git a/programs/scilab.json b/programs/scilab.json new file mode 100644 index 0000000..f048388 --- /dev/null +++ b/programs/scilab.json @@ -0,0 +1,10 @@ +{ + "files": [ + { + "path": "$HOME/.Scilab", + "movable": true, + "help": "Export the following environment variable:\n\n```bash\nexport SCIHOME=\"$XDG_STATE_HOME\"/scilab\n```\n" + } + ], + "name": "scilab" +} diff --git a/programs/vim.json b/programs/vim.json index f6f20ff..5d9475a 100644 --- a/programs/vim.json +++ b/programs/vim.json @@ -1,7 +1,7 @@ { "files": [ { - "help": "Since 7.3.1178 vim will search for ~/.vim/vimrc if ~/.vimrc is not found.\n\n\"$XDG_CONFIG_HOME\"/vim/vimrc\n```vim\nset runtimepath^=$XDG_CONFIG_HOME/vim\nset runtimepath+=$XDG_DATA_HOME/vim\nset runtimepath+=$XDG_CONFIG_HOME/vim/after\n\nset packpath^=$XDG_DATA_HOME/vim,$XDG_CONFIG_HOME/vim\nset packpath+=$XDG_CONFIG_HOME/vim/after,$XDG_DATA_HOME/vim/after\n\nlet g:netrw_home = $XDG_DATA_HOME.\"/vim\"\ncall mkdir($XDG_DATA_HOME.\"/vim/spell\", 'p')\n\nset backupdir=$XDG_STATE_HOME/vim/backup | call mkdir(&backupdir, 'p')\nset directory=$XDG_STATE_HOME/vim/swap | call mkdir(&directory, 'p')\nset undodir=$XDG_STATE_HOME/vim/undo | call mkdir(&undodir, 'p')\nset viewdir=$XDG_STATE_HOME/vim/view | call mkdir(&viewdir, 'p')\n\nif !has('nvim') | set viminfofile=$XDG_STATE_HOME/vim/viminfo | endif\n```\n\n~/.profile\n```\nexport GVIMINIT='let $MYGVIMRC=\"$XDG_CONFIG_HOME/vim/gvimrc\" | source $MYGVIMRC'\nexport VIMINIT='let $MYVIMRC=\"$XDG_CONFIG_HOME/vim/vimrc\" | source $MYVIMRC'\n```\n[G]VIMINIT environment variable will also affect Neovim. If separate configs for Vim and Neovim are desired then the following will be a better choice:\n\n```\nexport GVIMINIT='let $MYGVIMRC = !has(\"nvim\") ? \"$XDG_CONFIG_HOME/vim/gvimrc\" : \"$XDG_CONFIG_HOME/nvim/init.gvim\" | so $MYGVIMRC'\nexport VIMINIT='let $MYVIMRC = !has(\"nvim\") ? \"$XDG_CONFIG_HOME/vim/vimrc\" : \"$XDG_CONFIG_HOME/nvim/init.vim\" | so $MYVIMRC'\n```\n\nAdditional information:\nhttps://blog.joren.ga/vim-xdg\nhttps://tlvince.com/vim-respect-xdg\n", + "help": "Since 7.3.1178 vim will search for ~/.vim/vimrc if ~/.vimrc is not found.\n\n\"$XDG_CONFIG_HOME\"/vim/vimrc\n```vim\nset runtimepath^=$XDG_CONFIG_HOME/vim\nset runtimepath+=$XDG_DATA_HOME/vim\nset runtimepath+=$XDG_CONFIG_HOME/vim/after\n\nset packpath^=$XDG_DATA_HOME/vim,$XDG_CONFIG_HOME/vim\nset packpath+=$XDG_CONFIG_HOME/vim/after,$XDG_DATA_HOME/vim/after\n\nlet g:netrw_home = $XDG_DATA_HOME.\"/vim\"\ncall mkdir($XDG_DATA_HOME.\"/vim/spell\", 'p')\n\nset backupdir=$XDG_STATE_HOME/vim/backup | call mkdir(&backupdir, 'p')\nset directory=$XDG_STATE_HOME/vim/swap | call mkdir(&directory, 'p')\nset undodir=$XDG_STATE_HOME/vim/undo | call mkdir(&undodir, 'p')\nset viewdir=$XDG_STATE_HOME/vim/view | call mkdir(&viewdir, 'p')\n\nif !has('nvim') | set viminfofile=$XDG_STATE_HOME/vim/viminfo | endif\n```\n\n~/.profile\n```\nexport GVIMINIT='let $MYGVIMRC=\"$XDG_CONFIG_HOME/vim/gvimrc\" | source $MYGVIMRC'\nexport VIMINIT='let $MYVIMRC=\"$XDG_CONFIG_HOME/vim/vimrc\" | source $MYVIMRC'\n```\n[G]VIMINIT environment variable will also affect Neovim. If separate configs for Vim and Neovim are desired then the following will be a better choice:\n\n```\nexport GVIMINIT='let $MYGVIMRC = !has(\"nvim\") ? \"$XDG_CONFIG_HOME/vim/gvimrc\" : \"$XDG_CONFIG_HOME/nvim/init.gvim\" | so $MYGVIMRC'\nexport VIMINIT='let $MYVIMRC = !has(\"nvim\") ? \"$XDG_CONFIG_HOME/vim/vimrc\" : \"$XDG_CONFIG_HOME/nvim/init.vim\" | so $MYVIMRC'\n```\n\nAdditional information:\nhttps://jorengarenar.github.io/blog/vim-xdg\nhttps://tlvince.com/vim-respect-xdg\n", "movable": true, "path": "$HOME/.vimrc" }, @@ -17,4 +17,4 @@ } ], "name": "vim" -} \ No newline at end of file +} diff --git a/programs/xinit.json b/programs/xinit.json index 2ee1e63..fd0cf68 100644 --- a/programs/xinit.json +++ b/programs/xinit.json @@ -2,14 +2,14 @@ "files": [ { "help": "Export the following environment variable:\n\n```bash\nexport XSERVERRC=\"$XDG_CONFIG_HOME\"/X11/xserverrc\n```\n", - "movable": false, + "movable": true, "path": "$HOME/.xserverrc" }, { "help": "Export the following environment variable:\n\n```bash\nexport XINITRC=\"$XDG_CONFIG_HOME\"/X11/xinitrc\n```\n", - "movable": false, + "movable": true, "path": "$HOME/.xinitrc" } ], "name": "xinit" -} \ No newline at end of file +} diff --git a/programs/xorg-xrdb.json b/programs/xorg-xrdb.json index 63c29d2..14dacf9 100644 --- a/programs/xorg-xrdb.json +++ b/programs/xorg-xrdb.json @@ -4,6 +4,11 @@ "path": "$HOME/.Xresources", "movable": true, "help": "xrdb loads these resources, wherever you call xrdb, add this flag:\n\n```bash\nxrdb -load \"$XDG_CONFIG_HOME/X11/xresources\"\n```\n\n_Note: It will probably be called by your Xsession file._\n" + }, + { + "path": "$HOME/.Xdefaults", + "movable": true, + "help": "Old version of .Xresources. xrdb loads these resources, wherever you call xrdb, add this flag:\n\n```bash\nxrdb -load \"$XDG_CONFIG_HOME/X11/xresources\"\n```\n\n_Note: It will probably be called by your Xsession file._\n" } ], "name": "xorg-xrdb" diff --git a/programs/zap-proxy.json b/programs/zap-proxy.json new file mode 100644 index 0000000..a3d6044 --- /dev/null +++ b/programs/zap-proxy.json @@ -0,0 +1,11 @@ +{ + "name": "ZAP Proxy", + "files": [ + { + "path": "$HOME/.ZAP", + "movable": false, + "help": "Currently unsupported.\n\n_Relevant issue:_ https://github.com/zaproxy/zaproxy/issues/7718" + } + ] +} + diff --git a/xdg-ninja.sh b/xdg-ninja.sh index 8780de7..84260f5 100755 --- a/xdg-ninja.sh +++ b/xdg-ninja.sh @@ -123,14 +123,32 @@ apply_shell_expansion() { eval "$command" } -# Returns 0 if the path doesn't lead anywhere -# Returns 1 if the path leads to something -check_if_file_exists() { - FILE_PATH=$(apply_shell_expansion "$1") - if [ -e "$FILE_PATH" ]; then +# Function to check if a string contains shell pattern matching +has_pattern() { + case $1 in + *\** | *\?* | *\[*\]*) + return 0 + ;; + *) return 1 + ;; + esac +} + +# Returns the actual name of the given file that is on the user's disk +# This command applies shell pattern matching and return the actual filename +retrieve_existing_filename() { + FILE_PATH=$(apply_shell_expansion "$1") + + # return filename if found, nothing else + if has_pattern "$FILE_PATH"; then + dir="$(dirname "$FILE_PATH")" + part="$(basename "$FILE_PATH")" + find "$dir" -maxdepth 1 -name "$part" -print -quit 2>/dev/null else - return 0 + if [ -e "$FILE_PATH" ]; then + printf "%s" "$FILE_PATH" + fi fi } @@ -186,30 +204,24 @@ check_file() { MOVABLE="$3" HELP="$4" - check_if_file_exists "$FILENAME" - - case $? in + file=$(retrieve_existing_filename "$FILENAME") - 0) - log SUCS "$NAME" "$FILENAME" "$HELP" - ;; - - 1) + if [ "$file" ]; then if [ "$MOVABLE" = true ]; then - log ERR "$NAME" "$FILENAME" "$HELP" + log ERR "$NAME" "$file" "$HELP" else - log WARN "$NAME" "$FILENAME" "$HELP" + log WARN "$NAME" "$file" "$HELP" fi if [ "$HELP" ]; then if [ "$MOVABLE" = true ] || [ "$SKIP_UNSUPPORTED" = false ]; then - log HELP "$NAME" "$FILENAME" "$HELP" + log HELP "$NAME" "$file" "$HELP" fi else - log HELP "$NAME" "$FILENAME" "_No help available._" + log HELP "$NAME" "$file" "_No help available._" fi - ;; - - esac + else + log SUCS "$NAME" "$file" "$HELP" + fi } # Reads files from programs/, calls check_file on each file specified for each program