This commit is contained in:
parent
c449dfcb5f
commit
559939e2f4
49 changed files with 729 additions and 252 deletions
13
.config/zsh/cd_hooks/hicpu_mount
Normal file
13
.config/zsh/cd_hooks/hicpu_mount
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# shellcheck disable=SC2164,SC2168
|
||||
|
||||
local DIRNAME="$HOME/Services/cpu"
|
||||
|
||||
cd::enter() {
|
||||
! mount | grep -q "$DIRNAME" && mount "$DIRNAME" && builtin cd -q "$DIRNAME"
|
||||
}
|
||||
|
||||
cd::leave() {
|
||||
! fuser -m "$DIRNAME" >/dev/null 2>&1 && umount "$DIRNAME"
|
||||
}
|
||||
|
||||
# vim: ft=sh
|
||||
14
.config/zsh/cd_hooks/higpu_mount
Normal file
14
.config/zsh/cd_hooks/higpu_mount
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# shellcheck disable=SC2168
|
||||
|
||||
local DIRNAME="$HOME/Services/gpu"
|
||||
local MOUNT_DIRNAME="$DIRNAME/.volumes"
|
||||
|
||||
cd::enter() {
|
||||
! mount | grep -q "$MOUNT_DIRNAME" && mount "$MOUNT_DIRNAME"
|
||||
}
|
||||
|
||||
cd::leave() {
|
||||
! fuser "$DIRNAME" >/dev/null 2>&1 && umount "$MOUNT_DIRNAME"
|
||||
}
|
||||
|
||||
# vim: ft=sh
|
||||
73
.config/zsh/cd_hooks/university
Normal file
73
.config/zsh/cd_hooks/university
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
local DIRNAME="$HOME/University/"
|
||||
|
||||
mode::enable() {
|
||||
local mode_path="$DIRNAME/$1/.env"
|
||||
export MODE__ACTIVE_MODE="$1"
|
||||
export MODE__OLD_PS1="$PS1"
|
||||
|
||||
export PS1="($1) $PS1"
|
||||
|
||||
. "$mode_path"
|
||||
}
|
||||
|
||||
|
||||
mode::get_functions() {
|
||||
perl -ne '/^(?>function\s+)?([\x21-\x7e]+)\s*\(\)/ && print "$1\n"' < "$1"
|
||||
}
|
||||
|
||||
mode::get_variables() {
|
||||
perl -ne '/^(?>declare\s+(?>--?\w+\s*)+\s*)?\s*([\x21-\x3c\x3e-\x7e]+)=.*$/ && print "$1\n"' < "$1"
|
||||
}
|
||||
|
||||
mode::get_aliases() {
|
||||
perl -ne '/^(?:noglob\s+)?alias ([\x21-\x3c\x3e-\x7e]+)=(.*)\n/ && print "$1=$2\n"' < "$1"
|
||||
}
|
||||
|
||||
mode::disable() {
|
||||
export PS1="$MODE__OLD_PS1"
|
||||
local mode_path="$DIRNAME/$MODE__ACTIVE_MODE/.env"
|
||||
|
||||
unset -v "MODE__OLD_PS1"
|
||||
unset -v "MODE__ACTIVE_MODE"
|
||||
|
||||
for mode_variable in ${(@f)"$(mode::get_variables "$mode_path")"}; do
|
||||
unset "$mode_variable"
|
||||
done
|
||||
|
||||
for mode_function in ${(@f)"$(mode::get_functions "$mode_path")"}; do
|
||||
unset -f "$mode_function"
|
||||
done
|
||||
|
||||
for mode_alias in ${(@f)"$(mode::get_aliases "$mode_path")"}; do
|
||||
unalias "${mode_alias%=*}"
|
||||
done
|
||||
}
|
||||
|
||||
cd::enter() {
|
||||
[ -n "$MODE__ACTIVE_MODE" ] && mode::disable
|
||||
local module_name="$(cut -d/ -f1 <<<"${PWD#"$DIRNAME"}" )"
|
||||
[ ! -f "$DIRNAME/$module_name/.env" ] && return
|
||||
mode::enable "$module_name"
|
||||
}
|
||||
|
||||
cd::leave() {
|
||||
[ -n "$MODE__ACTIVE_MODE" ] && mode::disable
|
||||
}
|
||||
|
||||
m() {
|
||||
[ -z "$MODE__ACTIVE_MODE" ] && return 1
|
||||
|
||||
local mode_path="$DIRNAME/$MODE__ACTIVE_MODE/.env"
|
||||
|
||||
for type in Aliases Functions Variables; do
|
||||
local arr=(${(@f)"$(mode::get_"${type:l}" "$mode_path")"})
|
||||
|
||||
[ "${#arr}" -gt 0 ] && {
|
||||
echo "$type:"
|
||||
printf '%s\n' "${arr[@]}"
|
||||
echo
|
||||
}
|
||||
done | head -n -1
|
||||
}
|
||||
|
||||
# vim: ft=zsh
|
||||
Loading…
Add table
Add a link
Reference in a new issue