Skip to content

Commit

Permalink
load [cmd].bash after load os_any.bash
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlivio committed Aug 22, 2023
1 parent 45effd0 commit 2191bf4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,30 @@ flowchart LR
subgraph bash-helpers
init["init.sh"]
any["os_any.bash"]
win["os_win.bash"]
ubu["os_ub.bash"]
mac["os_mac.bash"]
command-dependent["
commands/COMMAND_NAME_1.bash
commands/COMMAND_NAME_2.bash
commands/[cmd_name].bash
...
"]
win["os_win.bash"]
ubu["os_ub.bash"]
mac["os_mac.bash"]
scripts_sh["
scripts/SCRIPT_1.sh
scripts/[script].sh
...
"]
scripts_ps1["
scripts/SCRIPT_1.ps1
scripts/win_[script].ps1
...
"]
end
bashrc --> |"load"| init
init --> |"load"| any
any --> |"alias to each *.sh"| scripts_sh
win --> |"alias to each *.ps1"| scripts_ps1
init --> |"if $OSTYPE==msys* || -n $WSL_DISTRO_NAME then load"| win
init --> |"if $OSTYPE==linux* then load"| ubu
init --> |"if $OSTYPE==mac* then load"| mac
init --> |"if type COMMAND_NAME then load"| command-dependent
win --> |"alias to each win_*.ps1"| scripts_ps1
init --> |"load if $OSTYPE==msys* || -n $WSL_DISTRO_NAME"| win
init --> |"load if $OSTYPE==linux*"| ubu
init --> |"load if $OSTYPE==mac*"| mac
init --> |"load if type cmd_name"| command-dependent
```

## Install
Expand Down
28 changes: 16 additions & 12 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@
BH_DIR="$(dirname "${BASH_SOURCE[0]}")"

#########################
# load os_<name>.bash files
# load os_any.bash
#########################

source "$BH_DIR/os_any.bash"

#########################
# load <command>.bash files
#########################

for file in "$BH_DIR/commands/"*.bash; do
command_name=$(basename ${file%.*})
if type $command_name &>/dev/null; then
source $file
fi
done

#########################
# load any os_<name>.bash files
#########################

if [[ $OSTYPE == msys* || -n $WSL_DISTRO_NAME ]]; then
source "$BH_DIR/os_win.bash"
fi
Expand All @@ -19,14 +34,3 @@ fi
if [[ $OSTYPE == darwin* ]]; then
"$BH_DIR/os_mac.bash"
fi

#########################
# load <command>.bash files
#########################

for file in "$BH_DIR/commands/"*.bash; do
command_name=$(basename ${file%.*})
if type $command_name &>/dev/null; then
source $file
fi
done

0 comments on commit 2191bf4

Please sign in to comment.