Last active
December 18, 2024 21:40
-
-
Save elmimmo/dc38b811239c4350924ea42c5fdde6ab to your computer and use it in GitHub Desktop.
Run adjacent command-line program from custom directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
: ${run_dir:="${HOME}/Library/Application Support/CUSTOM_DIRECTORY"} | |
# Find absolute path to script | |
script_path=$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}") | |
if [ -n "$(readlink "$script_path")" ]; then | |
script_path=$(readlink "$script_path") | |
fi | |
mkdir -p "$run_dir" && cd "$_" | |
"${script_path%.*}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In macOS, double-clicking a command-line program will open it in Terminal and run it from the Home folder, potentially polluting it with whatever output it might create there.
In order to easily have a command-line program run from a custom directory:
.tool
suffix.chmod +x
followed by space and dropping the script file in the Terminal window.run_dir
between quotes is the path you want to run the command-line program from.From then on, run the program by double-clicking the script in order to have it ran from the custom directory.