diff --git a/alf b/alf index f1aef3f..f9eb830 100755 --- a/alf +++ b/alf @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# This script was generated by bashly 1.2.6 (https://bashly.dannyb.co) +# This script was generated by bashly 1.2.7 (https://bashly.dannyb.co) # Modifying it manually is not recommended # :wrapper.bash3_bouncer @@ -347,6 +347,20 @@ normalize_input() { done } +# :command.inspect_args +inspect_args() { + if ((${#args[@]})); then + readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) + echo args: + for k in "${sorted_keys[@]}"; do + echo "- \${args[$k]} = ${args[$k]}" + done + else + echo args: none + fi + +} + # :command.user_lib # src/lib/colors.sh print_in_color() { @@ -365,20 +379,29 @@ yellow() { print_in_color "\e[33m" "$*"; } blue() { print_in_color "\e[34m" "$*"; } magenta() { print_in_color "\e[35m" "$*"; } cyan() { print_in_color "\e[36m" "$*"; } +black() { print_in_color "\e[30m" "$*"; } +white() { print_in_color "\e[37m" "$*"; } + bold() { print_in_color "\e[1m" "$*"; } underlined() { print_in_color "\e[4m" "$*"; } + red_bold() { print_in_color "\e[1;31m" "$*"; } green_bold() { print_in_color "\e[1;32m" "$*"; } yellow_bold() { print_in_color "\e[1;33m" "$*"; } blue_bold() { print_in_color "\e[1;34m" "$*"; } magenta_bold() { print_in_color "\e[1;35m" "$*"; } cyan_bold() { print_in_color "\e[1;36m" "$*"; } +black_bold() { print_in_color "\e[1;30m" "$*"; } +white_bold() { print_in_color "\e[1;37m" "$*"; } + red_underlined() { print_in_color "\e[4;31m" "$*"; } green_underlined() { print_in_color "\e[4;32m" "$*"; } yellow_underlined() { print_in_color "\e[4;33m" "$*"; } blue_underlined() { print_in_color "\e[4;34m" "$*"; } magenta_underlined() { print_in_color "\e[4;35m" "$*"; } cyan_underlined() { print_in_color "\e[4;36m" "$*"; } +black_underlined() { print_in_color "\e[4;30m" "$*"; } +white_underlined() { print_in_color "\e[4;37m" "$*"; } # src/lib/find_config.sh find_config() { @@ -556,6 +579,7 @@ save_config() { # :command.function alf_connect_command() { + # src/connect_command.sh repo=${args[repo]} force=${args[--yes]} force_ssh=${args[--ssh]} @@ -646,6 +670,7 @@ alf_connect_command() { # :command.function alf_download_command() { + # src/download_command.sh find_config if [[ ! -f $rc_file ]]; then @@ -665,6 +690,7 @@ alf_download_command() { # :command.function alf_upload_command() { + # src/upload_command.sh find_config if [[ ! -f $rc_file ]]; then @@ -683,6 +709,7 @@ alf_upload_command() { # :command.function alf_generate_command() { + # src/generate_command.sh generate_config } @@ -690,6 +717,7 @@ alf_generate_command() { # :command.function alf_save_command() { + # src/save_command.sh save_config } @@ -697,6 +725,7 @@ alf_save_command() { # :command.function alf_edit_command() { + # src/edit_command.sh find_config ${EDITOR:-vi} "$config_file" } @@ -704,6 +733,7 @@ alf_edit_command() { # :command.function alf_which_command() { + # src/which_command.sh code=${args[code]} subcode=${args[subcode]} @@ -740,6 +770,7 @@ alf_which_command() { # :command.function alf_upgrade_command() { + # src/upgrade_command.sh exec bash <(curl -s https://raw.githubusercontent.com/DannyBen/alf/master/setup) } @@ -747,6 +778,7 @@ alf_upgrade_command() { # :command.function alf_info_command() { + # src/info_command.sh find_config if [[ -d "$repo_path/.git" ]]; then @@ -947,9 +979,14 @@ alf_connect_parse_requirements() { done # :command.dependencies_filter + missing_deps= # :dependency.filter if ! command -v git >/dev/null 2>&1; then printf "missing dependency: git\n" >&2 + missing_deps=1 + fi + + if [[ -n $missing_deps ]]; then exit 1 fi @@ -1005,6 +1042,7 @@ alf_connect_parse_requirements() { esac done + # :command.required_args_filter if [[ -z ${args['repo']+x} ]]; then printf "missing required argument: REPO\nusage: alf connect REPO [OPTIONS]\n" >&2 @@ -1034,9 +1072,14 @@ alf_download_parse_requirements() { done # :command.dependencies_filter + missing_deps= # :dependency.filter if ! command -v git >/dev/null 2>&1; then printf "missing dependency: git\n" >&2 + missing_deps=1 + fi + + if [[ -n $missing_deps ]]; then exit 1 fi @@ -1086,9 +1129,14 @@ alf_upload_parse_requirements() { done # :command.dependencies_filter + missing_deps= # :dependency.filter if ! command -v git >/dev/null 2>&1; then printf "missing dependency: git\n" >&2 + missing_deps=1 + fi + + if [[ -n $missing_deps ]]; then exit 1 fi @@ -1307,6 +1355,7 @@ alf_which_parse_requirements() { esac done + # :command.required_args_filter if [[ -z ${args['code']+x} ]]; then printf "missing required argument: CODE\nusage: alf which CODE [SUBCODE]\n" >&2 @@ -1336,9 +1385,14 @@ alf_upgrade_parse_requirements() { done # :command.dependencies_filter + missing_deps= # :dependency.filter if ! command -v curl >/dev/null 2>&1; then printf "missing dependency: curl\n" >&2 + missing_deps=1 + fi + + if [[ -n $missing_deps ]]; then exit 1 fi @@ -1388,9 +1442,14 @@ alf_info_parse_requirements() { done # :command.dependencies_filter + missing_deps= # :dependency.filter if ! command -v git >/dev/null 2>&1; then printf "missing dependency: git\n" >&2 + missing_deps=1 + fi + + if [[ -n $missing_deps ]]; then exit 1 fi @@ -1426,6 +1485,11 @@ initialize() { long_usage='' set -e + # :command.globals + declare -g -A args=() + declare -g -a input=() + + # src/initialize.sh aliases_file=${ALF_ALIASES_FILE:-~/.bash_aliases} rc_file=${ALF_RC_FILE:-~/.alfrc} set -e @@ -1434,8 +1498,6 @@ initialize() { # :command.run run() { - declare -g -A args=() - declare -g -a input=() normalize_input "$@" parse_requirements "${input[@]}" @@ -1452,5 +1514,7 @@ run() { esac } -initialize -run "$@" +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + initialize + run "$@" +fi diff --git a/setup b/setup index a53a318..b48e9e4 100755 --- a/setup +++ b/setup @@ -19,19 +19,18 @@ section() { printf "\n=== %s\n" "$(green_bold "$@")" } -copy() { - printf "%s => %s\n" "$(blue "$(printf '%-25s' "$1")")" "$2" - cp "$1" "$2" -} - sudo_copy() { printf "%s => %s\n" "$(blue "$(printf '%-25s' "$1")")" "$2" - $sudo cp "$1" "$2" + + if [[ -n "$3" ]]; then + $sudo install -m "$3" "$1" "$2" + else + $sudo install "$1" "$2" + fi } copy_executable() { - sudo_copy "$1" "/usr/local/bin/" - $sudo chmod a+x "/usr/local/bin/$1" + sudo_copy "$1" "/usr/local/bin/" "755" } copy_man() { diff --git a/src/lib/colors.sh b/src/lib/colors.sh index cbdc015..7458e2d 100644 --- a/src/lib/colors.sh +++ b/src/lib/colors.sh @@ -26,17 +26,26 @@ yellow() { print_in_color "\e[33m" "$*"; } blue() { print_in_color "\e[34m" "$*"; } magenta() { print_in_color "\e[35m" "$*"; } cyan() { print_in_color "\e[36m" "$*"; } +black() { print_in_color "\e[30m" "$*"; } +white() { print_in_color "\e[37m" "$*"; } + bold() { print_in_color "\e[1m" "$*"; } underlined() { print_in_color "\e[4m" "$*"; } + red_bold() { print_in_color "\e[1;31m" "$*"; } green_bold() { print_in_color "\e[1;32m" "$*"; } yellow_bold() { print_in_color "\e[1;33m" "$*"; } blue_bold() { print_in_color "\e[1;34m" "$*"; } magenta_bold() { print_in_color "\e[1;35m" "$*"; } cyan_bold() { print_in_color "\e[1;36m" "$*"; } +black_bold() { print_in_color "\e[1;30m" "$*"; } +white_bold() { print_in_color "\e[1;37m" "$*"; } + red_underlined() { print_in_color "\e[4;31m" "$*"; } green_underlined() { print_in_color "\e[4;32m" "$*"; } yellow_underlined() { print_in_color "\e[4;33m" "$*"; } blue_underlined() { print_in_color "\e[4;34m" "$*"; } magenta_underlined() { print_in_color "\e[4;35m" "$*"; } cyan_underlined() { print_in_color "\e[4;36m" "$*"; } +black_underlined() { print_in_color "\e[4;30m" "$*"; } +white_underlined() { print_in_color "\e[4;37m" "$*"; }