Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: "one sub" should be enabled/disabled by users
- Loading branch information
Showing
7 changed files
with
113 additions
and
127 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
usage_list() { | ||
cat <<EOF | ||
Usage: one sub list | ||
Desc: List executable files in each REPO/sub | ||
EOF | ||
} | ||
|
||
complete_list() { | ||
echo '-f' | ||
} | ||
|
||
list() { | ||
local path repo | ||
|
||
# shellcheck disable=2153 | ||
for path in "${ONE_DIR}"/enabled/sub/*; do | ||
printf '%b%20s%b -> %b%s\n' \ | ||
"$GREEN" "$(basename "$path")" "$GREY"\ | ||
"$WHITE" "$(readlink "$path")" | ||
done | ||
} | ||
|
||
list_sub() { | ||
shopt -s nullglob | ||
local path repo name link repo_name | ||
|
||
for repo in "${ONE_DIR}"/enabled/repos/* ; do | ||
repo_name=$(basename "$repo") | ||
printf '%b[%s]%b' "$BLUE" "$repo_name" "$RESET_ALL" | ||
|
||
for path in "$repo/sub"/* ; do | ||
name=$(basename "$path" '.opt.bash') | ||
link=${ONE_DIR}/enabled/sub/$name | ||
|
||
if [[ -h "$link" ]] && [[ $(readlink "$link") == "$path" ]]; then | ||
printf ' %b%s%b' "$BOLD_GREEN" "$name" "$RESET_ALL" | ||
else | ||
printf ' %s' "$name" | ||
fi | ||
done | ||
printf '\n' | ||
done | ||
|
||
printf "\n### The %bGREEN%b items are enabled. The WHITE items are availabled. ###\n" "$BOLD_GREEN" "$RESET_ALL" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
set -o errexit -o nounset -o pipefail -o errtrace | ||
(shopt -p inherit_errexit &>/dev/null) && shopt -s inherit_errexit | ||
|
||
if [[ -z ${ONE_DIR:-} ]]; then | ||
SCRIPT_DIR="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" | ||
readonly SCRIPT_DIR | ||
export ONE_DIR=$SCRIPT_DIR/.. | ||
fi | ||
|
||
# shellcheck source=../../one-cmds/util.bash | ||
. "$ONE_DIR/one-cmds/util.bash" | ||
|
||
actions=(list info enable disable which) | ||
|
||
declare -A alias_map=( | ||
['e']=enable | ||
['d']=disable | ||
['l']=list | ||
['i']=info | ||
['w']=which | ||
) | ||
|
||
# one.bash:completion | ||
parse_completion sub actions "$@" | ||
# one.bash:usage | ||
parse_cmd sub "$@" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
usage() { | ||
cat <<EOF | ||
Usage: one sub [-h|--help] <ACTION> | ||
one sub [-h|--help] | ||
Desc: Manage ONE_SUB commands | ||
ACTION: | ||
e, enable Enable matched executable files | ||
d, disable Disable matched executable files | ||
l, list List executable files in each REPO/sub | ||
i, info Show info of matched executable files | ||
w, which <NAME> Show realpath of executable files | ||
EOF | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
usage_which() { | ||
cat <<EOF | ||
Usage: one sub which <cmd> | ||
Desc: Show filepath of <cmd> | ||
EOF | ||
} | ||
|
||
complete_which() { | ||
# shellcheck source=../../bash/load-config.bash | ||
. "$ONE_DIR/bash/load-config.bash" | ||
one sub list | ||
} | ||
|
||
which_sub() { | ||
local name=$1 | ||
local path | ||
|
||
for path in "$ONE_DIR"/enabled/repos/*/sub/"$name"; do | ||
if [[ -x $path ]]; then | ||
echo "$path" | ||
fi | ||
done | ||
} |