I've set up a script in my ~/.bashrc to help organize my directories and files after running xdg-ninja. I'm looking for some feedback from more experienced users to ensure it's working as it should. Here's a simplified version of what I've created, specifically focusing on the 'cargo' example:
```bash
#! /usr/bin/env dash
# xdg-ninja alias
alias 'xdg-ninja'='xdg-ninja --skip-ok --skip-unsupported' ;
# XDG Base Directory Specification
export XDG_CACHE_HOME="${HOME}/.cache" ;
export XDG_CONFIG_HOME="${HOME}/.config" ;
export XDG_DATA_HOME="${HOME}/.local/share" ;
export XDG_STATE_HOME="${HOME}/.local/state" ;
# xdgmv function to move files/directories
xdgmv () {
test "${#}" -ne '2' && return ; test -e "${1}" || return ;
if test -d "${2%}" ;
then
mv --backup='numbered' --force "${1}" "${2}" ;
else
mkdir -p "${2%}" && mv --backup='numbered' --force "${1}" "${2}" ;
fi ;
}
# Move cargo directory
xdgmv "${HOME}/.cargo" "${XDG_DATA_HOME}/cargo" &&
export CARGO_HOME="${XDG_DATA_HOME}/cargo" ;
# Clear xdgmv function
unset xdgmv ;
```
Would love to hear any thoughts on this configuration!
1 Answer
Your setup generally looks solid! While nothing is entirely foolproof, I don’t see major issues. Just a couple of tips:
1. It’s usually better to provide some feedback when a command fails. This helps prevent users from mistakenly thinking a command was successful when it wasn’t.
2. Try to minimize duplicated code for better maintainability. For example, you can check if the destination directory exists and create it in one go, then carry on with the move command. Here’s a quick refactor:
```bash
if test -d "${2%/*}" ;
then
mkdir -p "${2%/*}"
fi
mv --backup='numbered' --force "${1}" "${2}" ;
```
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String