Commit 70e3b18d by Gianluca LOMBARDI

Allow cross-platform compatibility

parent 3bcca1e2
......@@ -35,7 +35,7 @@ To execute the scripts from any directory, source `gemme-utils.sh` file:
. /path/to/this/directory/gemme-utils.sh
```
To ensure the script loads every time you open a terminal, add the above line at the end it to the `~/.bashrc` or `~/.zshrc` file.
To ensure the script loads every time you open a terminal, add the above line at the end iof the `~/.bashrc` or `~/.zshrc` file.
The command defines a new variable `GU_PATH` pointing to this directory, and a function `gemme-utils` for scripts execution. It also enables bash completion to list available scripts. Custom python scripts saved in this directory will be visible and executable as well.
......
# Set GU_PATH to this directory
export GU_PATH=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
export GU_PATH="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
# Function to execute Python scripts from GU_PATH
......@@ -18,31 +18,18 @@ gemme-utils() {
}
# Bash Completion Function for gemme-utils
_gemme_utils_complete() {
_complete_scripts() {
local cur=${COMP_WORDS[COMP_CWORD]}
local scripts
mapfile -t scripts < <(find "$GU_PATH" -maxdepth 1 -type f -name "*.py" -exec basename {} \;)
COMPREPLY=( $(compgen -W "${scripts[*]}" -- "$cur") )
}
_complete_default() {
local script=${COMP_WORDS[1]}
local cur=${COMP_WORDS[COMP_CWORD]}
if [ -f "$GU_PATH/$script" ]; then
COMPREPLY=( $(compgen -f -- $cur) ) # Default suggestion
fi
}
if [ ${COMP_CWORD} -eq 1 ]; then
_complete_scripts
if [[ $COMP_CWORD -eq 1 ]]; then
local scripts=$(find "$GU_PATH" -maxdepth 1 -type f -name "*.py" -exec basename {} \; | tr '\n' ' ')
COMPREPLY=( $(compgen -W "$scripts" -- "$cur") )
else
_complete_default
# Suggest file paths if script exists
local script="${COMP_WORDS[1]}"
if [[ -f "$GU_PATH/$script" ]]; then
COMPREPLY=( $(compgen -f -- "$cur") )
fi
fi
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment