Skip to content

Commit

Permalink
add_sh_scripts_as_aliases and add_ps1_scripts_as_aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlivio committed Jul 24, 2023
1 parent b28d539 commit 0f77a8f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 36 deletions.
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,30 @@ The project logo refers to the synthetic chemical element Bohrium, which also ha
flowchart LR
bashrc["~/.bashrc"]
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/COMMAND_NAME_3.bash
...
"]
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
...
"]
scripts["
scripts/SCRIPT_1.ps1
scripts/SCRIPT_2.sh
...
"]
end
bashrc --> |"load"| init
init --> |"always load"|any
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 --> |"foreach in commands/*: if type COMMAND_NAME then load"|command-dependent
init --> |"load"| any
any --> |"alias *.sh"| scripts
win --> |"alias *.ps1"| scripts
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
```


Expand Down
3 changes: 1 addition & 2 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BH_DIR="$(dirname "${BASH_SOURCE[0]}")"
source "$BH_DIR/os_any.bash"

if [[ $OSTYPE == msys* || -n $WSL_DISTRO_NAME ]]; then
source "$BH_DIR/os_win.bash";
source "$BH_DIR/os_win.bash"
fi

if [[ $OSTYPE == linux* ]]; then
Expand All @@ -20,7 +20,6 @@ if [[ $OSTYPE == darwin* ]]; then
"$BH_DIR/os_mac.bash"
fi


#########################
# load <command>.bash files
#########################
Expand Down
15 changes: 15 additions & 0 deletions os_any.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
#########################
# load scripts as alias
#########################

function add_sh_scripts_as_aliases(){
for file in "$BH_DIR/scripts/"*.sh; do
if test -f $file &>/dev/null; then
script_name=$(basename ${file%.*})
eval "alias $script_name='sh $file'"
fi
done
}

add_sh_scripts_as_aliases

#########################
# basic
#########################
Expand Down
41 changes: 23 additions & 18 deletions os_win.bash
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
#########################
# basic
#########################

alias ls='ls --color=auto -I NTUSER\* -I ntuser\* -I AppData -I IntelGraphicsProfiles* -I MicrosoftEdgeBackups'
BH_LIB_PS1="$BH_DIR/scripts/"

if [[ -n $WSL_DISTRO_NAME ]]; then
alias winpath='wslpath -m'
elif [[ $OSTYPE == linux* ]]; then
alias winpath='cygpath -m'
fi

#########################
# load scripts as alias
#########################

function add_ps1_scripts_as_aliases(){
for file in "$BH_DIR/scripts/"win_*.ps1; do
if test -f $file &>/dev/null; then
script_name=$(basename ${file%.*})
eval "alias $script_name='powershell.exe $(winpath $file)'"
fi
done
}

add_ps1_scripts_as_aliases

#########################
# basic
#########################

alias ls='ls --color=auto -I NTUSER\* -I ntuser\* -I AppData -I IntelGraphicsProfiles* -I MicrosoftEdgeBackups'

function home_clean_win() {
if [[ -n $WSL_DISTRO_NAME ]]; then
home_clean $(wslpath $(wslvar USERPROFILE))
Expand Down Expand Up @@ -117,7 +131,7 @@ function win_path_add() { # using ps1 script
local dir=$(winpath "$@")
local dircyg=$(cygpath "$@")
# export in win
powershell.exe -c "$(winpath $BH_LIB_PS1/win_path_add.ps1)" \'$dir\'
powershell.exe -c "$(winpath $BH_DIR/scripts/win_path_add.ps1)" \'$dir\'
# export in bash (it will reolad from win in new shell)
if [[ ":$PATH:" != *":$dircyg:"* ]]; then export PATH=${PATH}:$dircyg; fi
}
Expand Down Expand Up @@ -151,13 +165,4 @@ function win_policy_reset() {
gsudo cmd.exe /C 'RD /S /Q %WinDir%\\System32\\GroupPolicyUsers '
gsudo cmd.exe /C 'RD /S /Q %WinDir%\System32\GroupPolicy '
gsudo gpupdate.exe /force
}

function ps1_script() { powershell.exe "$(winpath $BH_LIB_PS1/$1)"; }
function win_disable_apps_preinstalled() { ps1_script win_disable_apps_preinstalled.ps1; }
function win_disable_hotkeys() { ps1_script win_disable_hotkeys.ps1; }
function win_disable_password_policy() { ps1_script win_disable_password_policy.ps1; }
function win_disable_pc_folders() { ps1_script win_disable_pc_folders.ps1; }
function win_disable_sounds() { ps1_script win_disable_sounds.ps1; }
function win_enable_hyper_v() { ps1_script win_enable_hyper_v.ps1; }
function win_path_add() { ps1_script win_path_add.ps1; }
}

0 comments on commit 0f77a8f

Please sign in to comment.