From 13628d1efe32ef7c2b1155fa343b86f9170ac91a Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Sat, 13 Feb 2021 17:35:08 +0100 Subject: [PATCH 01/54] Paths are now loaded before everything --- dotfiles_template/shell/bash/.bashrc | 4 +++- dotfiles_template/shell/exports.sh | 19 ------------------- dotfiles_template/shell/paths.sh | 18 ++++++++++++++++++ dotfiles_template/shell/zsh/.zshrc | 3 +++ 4 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 dotfiles_template/shell/paths.sh diff --git a/dotfiles_template/shell/bash/.bashrc b/dotfiles_template/shell/bash/.bashrc index 467227a85..9a3bcfcad 100644 --- a/dotfiles_template/shell/bash/.bashrc +++ b/dotfiles_template/shell/bash/.bashrc @@ -14,7 +14,7 @@ if [[ "$(ps -p $$ -ocomm=)" =~ (bash$) ]]; then export PROMPT_COMMAND="__right_prompt" fi -source "$DOTFILES_PATH/shell/init.sh" +source "$DOTFILES_PATH/shell/paths.sh" PATH=$( IFS=":" @@ -22,6 +22,8 @@ PATH=$( ) export PATH +source "$DOTFILES_PATH/shell/init.sh" + themes_paths=( "$DOTFILES_PATH/shell/bash/themes" "$DOTLY_PATH/shell/bash/themes" diff --git a/dotfiles_template/shell/exports.sh b/dotfiles_template/shell/exports.sh index ce47e3e45..2feace546 100644 --- a/dotfiles_template/shell/exports.sh +++ b/dotfiles_template/shell/exports.sh @@ -6,22 +6,3 @@ export FZF_DEFAULT_OPTS=' --color=pointer:#ebdbb2,bg+:#3c3836,fg:#ebdbb2,fg+:#fbf1c7,hl:#8ec07c,info:#928374,header:#fb4934 --reverse ' - -export path=( - "$HOME/bin" - "$DOTLY_PATH/bin" - "$DOTFILES_PATH/bin" - "$JAVA_HOME/bin" - "$GEM_HOME/bin" - "$GOPATH/bin" - "$HOME/.cargo/bin" - "/usr/local/opt/ruby/bin" - "/usr/local/opt/python/libexec/bin" - "/opt/homebrew/bin" - "/usr/local/bin" - "/usr/local/sbin" - "/bin" - "/usr/bin" - "/usr/sbin" - "/sbin" -) diff --git a/dotfiles_template/shell/paths.sh b/dotfiles_template/shell/paths.sh new file mode 100644 index 000000000..11b30b606 --- /dev/null +++ b/dotfiles_template/shell/paths.sh @@ -0,0 +1,18 @@ +export path=( + "$HOME/bin" + "$DOTLY_PATH/bin" + "$DOTFILES_PATH/bin" + "$JAVA_HOME/bin" + "$GEM_HOME/bin" + "$GOPATH/bin" + "$HOME/.cargo/bin" + "/usr/local/opt/ruby/bin" + "/usr/local/opt/python/libexec/bin" + "/opt/homebrew/bin" + "/usr/local/bin" + "/usr/local/sbin" + "/bin" + "/usr/bin" + "/usr/sbin" + "/sbin" +) \ No newline at end of file diff --git a/dotfiles_template/shell/zsh/.zshrc b/dotfiles_template/shell/zsh/.zshrc index e3ef0f3f6..4f96e2ae0 100644 --- a/dotfiles_template/shell/zsh/.zshrc +++ b/dotfiles_template/shell/zsh/.zshrc @@ -1,6 +1,9 @@ # Uncomment for debuf with `zprof` # zmodload zsh/zprof +# Firstly Paths +source "$DOTFILES_PATH/shell/paths.sh" + # ZSH Ops setopt HIST_IGNORE_ALL_DUPS setopt HIST_FCNTL_LOCK From 2ab33fba83bed4d17a7acd087e868a6305bda850 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Sun, 28 Mar 2021 04:53:56 +0200 Subject: [PATCH 02/54] Core update, adding some functions that will be used with other features/fixes in other PRs. Added feature of autoupdate dotly --- bin/dotly | 43 +++++++++ dotfiles_template/shell/dotly-vars.sh | 3 + dotfiles_template/shell/exports.sh | 3 + scripts/core/_main.sh | 2 +- scripts/core/debug.sh | 28 ++++++ scripts/core/files.sh | 5 ++ scripts/core/output.sh | 56 +++++++++++- scripts/core/platform.sh | 38 ++++++++ scripts/core/templating.sh | 119 +++++++++++++++++++++++++ scripts/dotfiles/create | 22 +++-- scripts/self/init | 120 ++++++++++++++++++++++++++ scripts/self/utils/init.sh | 82 ++++++++++++++++++ shell/bash/init-dotly.sh | 48 +++++++++++ shell/init-scripts/autoupdate_loader | 4 + shell/zsh/init-dotly.sh | 32 +++++++ 15 files changed, 595 insertions(+), 10 deletions(-) create mode 100755 dotfiles_template/shell/dotly-vars.sh create mode 100644 scripts/core/debug.sh create mode 100644 scripts/core/files.sh create mode 100755 scripts/core/templating.sh create mode 100755 scripts/self/init create mode 100644 scripts/self/utils/init.sh create mode 100755 shell/bash/init-dotly.sh create mode 100755 shell/init-scripts/autoupdate_loader create mode 100755 shell/zsh/init-dotly.sh diff --git a/bin/dotly b/bin/dotly index 76175d76a..3f297a641 100755 --- a/bin/dotly +++ b/bin/dotly @@ -12,6 +12,49 @@ case $1 in "self-update") dot self update ;; +"autoupdate") + # Variables with default values + DOTLY_AUTO_UPDATE_DAYS=${DOTLY_AUTO_UPDATE_DAYS:-7} + DOTLY_AUTO_UPDATE_MODE=${DOTLY_AUTO_UPDATE_MODE:-reminder} # prompt + + # Other needed variables + CURRENT_DIR="$(pwd)" + + # Change to dotly path + cd "$DOTLY_PATH" + + if [[ $(date -r "$DOTLY_PATH" +%s) -lt $(date -d "now - $DOTLY_AUTO_UPDATE_DAYS days" +%s) ]] &&\ + git diff --quiet "origin/$(git branch --show-current)"; then + + output::empty_line + output::write " -------------------------------------------" + output::write "| 🥳🎉🍾 NEW DOTLY VERSION AVAILABLE 🥳🎉🍾 |" + output::write " -------------------------------------------" + output::empty_line + + case "$DOTLY_AUTO_UPDATE_MODE" in + "auto") + output::answer "🚀 Updating" + dot self update + output::solution "Updated" + ;; + "prompt") + output::yesno "Do you want to update now" &&\ + output::answer "🚀 Updating" &&\ + dot self update &&\ + output::solution "Updated" + ;; + *) + output::write "🚀 To update your current version just type:" + output::answer "dotly self-update" + ;; + esac + + output::empty_line + fi + + cd "$CURRENT_DIR" + ;; *) exit 1 ;; diff --git a/dotfiles_template/shell/dotly-vars.sh b/dotfiles_template/shell/dotly-vars.sh new file mode 100755 index 000000000..79d257a49 --- /dev/null +++ b/dotfiles_template/shell/dotly-vars.sh @@ -0,0 +1,3 @@ +export DOTFILES_PATH="XXX_DOTFILES_PATH_XXX" +export DOTLY_PATH="$DOTFILES_PATH/modules/dotly" +export DOTLY_THEME="codely" \ No newline at end of file diff --git a/dotfiles_template/shell/exports.sh b/dotfiles_template/shell/exports.sh index 2feace546..9599f55fa 100644 --- a/dotfiles_template/shell/exports.sh +++ b/dotfiles_template/shell/exports.sh @@ -1,3 +1,6 @@ +export DOTLY_AUTO_UPDATE_DAYS=7 +export DOTLY_AUTO_UPDATE_MODE="reminder" # reminder*, auto, prompt + export JAVA_HOME='/Library/Java/JavaVirtualMachines/amazon-corretto-15.jdk/Contents/Home' export GEM_HOME="$HOME/.gem" export GOPATH="$HOME/.go" diff --git a/scripts/core/_main.sh b/scripts/core/_main.sh index a220e6a16..523e177da 100755 --- a/scripts/core/_main.sh +++ b/scripts/core/_main.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash if ! ${DOT_MAIN_SOURCED:-false}; then - for file in $DOTLY_PATH/scripts/core/{args,collections,documentation,dot,git,log,platform,output,str}.sh; do + for file in $DOTLY_PATH/scripts/core/{args,collections,documentation,dot,files,git,log,platform,output,str}.sh; do source "$file"; done; unset file; diff --git a/scripts/core/debug.sh b/scripts/core/debug.sh new file mode 100644 index 000000000..c18f68695 --- /dev/null +++ b/scripts/core/debug.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +debug::out() { + echo "$@" +} + +debug::log() { + [[ ! -z "$DEBUG" ]] && debug::out "$@" +} + +debug::logg() { + DEBUG_LEVEL=${DEBUG_LEVEL:-1} + [[ $DEBUG_LEVEL -gt 1 ]] && debug::log $@ +} + +debug::log_exec() { + debug::log "Executing: ${@[@]}" + eval "${@[@]}" +} + +debug::set_variable () { + local var_name="$1" + shift + local values=$@ + eval "$var_name=${values[@]}" + + debug::logg "Set varible '$var_name' to '${values[@]}'" +} \ No newline at end of file diff --git a/scripts/core/files.sh b/scripts/core/files.sh new file mode 100644 index 000000000..54136cf93 --- /dev/null +++ b/scripts/core/files.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +files::check_if_path_is_older() { + [[ $(date -r "$1" +%s) -lt $(date -d "now - $2 days" +%s) ]] +} \ No newline at end of file diff --git a/scripts/core/output.sh b/scripts/core/output.sh index 4509bfa32..92620efe3 100644 --- a/scripts/core/output.sh +++ b/scripts/core/output.sh @@ -5,20 +5,68 @@ green='\033[0;32m' bold_blue='\033[1m\033[34m' normal='\033[0m' +platform::is_macos() { + [[ $(uname -s) == "Darwin" ]] +} + output::write() { local -r text="${1:-}" echo -e "$text" } -output::answer() { output::write " > $1"; } -output::error() { output::answer "${red}$1${normal}"; } -output::solution() { output::answer "${green}$1${normal}"; } +output::answer() { output::write " > $@"; } +output::error() { output::answer "${red}$@${normal}"; } +output::solution() { output::answer "${green}$@${normal}"; } output::question() { if [ platform::is_macos ]; then output::answer "🤔 $1: "; read -r "$2"; else - read -rp " $1: " "$2" + read -rp "🤔 $1: " "$2" + fi +} +output::question_default() { + local question="$1" + local default_value="$2" + local var_name="$3" + + output::question "$question? [$default_value]" "$var_name" + eval "$var_name=\"\${$var_name:-$default_value}\"" +} +output::yesno() { + local question="$1" + local default="${2:-Y}" + local PROMPT_REPLY values default_check + + if [[ "$default" =~ ^[Yy] ]]; then + values="Y/n" + default_check="Yy" + else + values="y/N" + default_check="Nn" fi + + output::question_default "$question" "$values" "PROMPT_REPLY" + [[ "$PROMPT_REPLY" =~ ^[$default_check] ]] } output::empty_line() { echo ''; } output::header() { output::empty_line; output::write "${bold_blue}---- $1 ----${normal}"; } +output::str_to_upper() { echo $@ | tr '[:lower:]' '[:upper:]'; } +# This only joins by one char as glue +#output::join() { local IFS="$1"; shift; echo "$*"; unset IFS; } +# split is not compatible with strings that have new space +output::split() { local IFS="$1"; shift; echo "${!@[@]}"; unset IFS; } +#This can join with string as glue +output::join() { + local glue="$1"; shift + local counter=0 + local IFS='' + for item in "$@"; do + counter=$(( $counter + 1 )) + echo -n -e "$item" + [[ $counter -ne $# ]] && echo -n -e "$glue" + done +} +# Usage: output::array_* "${arr1[@]}" "${arr2[@]}" +output::array_union() { echo "${@}" | tr ' ' '\n' | sort | uniq; } +output::array_disjunction() { echo "${@}" | tr ' ' '\n' | sort | uniq -u; } +output::array_difference() { echo "${@}" | tr ' ' '\n' | sort | uniq -d; } \ No newline at end of file diff --git a/scripts/core/platform.sh b/scripts/core/platform.sh index 2e0ba2c3f..ad140eb16 100644 --- a/scripts/core/platform.sh +++ b/scripts/core/platform.sh @@ -23,3 +23,41 @@ platform::is_wsl() { platform::wsl_home_path(){ wslpath "$(wslvar USERPROFILE 2> /dev/null)" } + +# Used as reference: https://gist.github.com/maxrimue/ca69ee78081645e1ef62 +platform::semver_compare() { + normalize_ver() { + echo "${${1//./ }//v/}" + } + + compare_ver() { + [[ $1 -lt $2 ]] && echo -1 && return + [[ $1 -gt $2 ]] && echo 1 && return + + echo 0 + } + + v1="$(normalize_ver $1)" + v2="$(normalize_ver $2)" + + major1="$(echo $v1 | awk '{print $1}')" + major2="$(echo $v2 | awk '{print $1}')" + + minor1="$(echo $v1 | awk '{print $2}')" + minor2="$(echo $v2 | awk '{print $2}')" + + patch1="$(echo $v1 | awk '{print $3}')" + patch2="$(echo $v2 | awk '{print $3}')" + + compare_major="$(compare_ver $major1 $major2)" + compare_minor="$(compare_ver $minor1 $minor2)" + compare_patch="$(compare_ver $patch1 $patch2)" + + if [[ $compare_major -ne 0 ]]; then + echo $compare_major + elif [[ $compare_minor -ne 0 ]]; then + echo $compare_minor + else + echo $compare_patch + fi +} \ No newline at end of file diff --git a/scripts/core/templating.sh b/scripts/core/templating.sh new file mode 100755 index 000000000..7f23dd685 --- /dev/null +++ b/scripts/core/templating.sh @@ -0,0 +1,119 @@ +#!/usr/bin/env bash + +# +# This set of functions are used for file/strings advanced templating +# +# Author: Gabriel Trabanco +# This was done, using "dot dotfiles create" as reference + + +# templating::replace_var [|] [value1 [... [valueN]] +# echo "template string" | templating::replace_var [value1 [... [valueN]] +# +# echo "Those are my family names: XXX_FAMILY_NAMES_XXX" |\ +# templating::replace_var family-names Miguel Manuel +# +# This will print: +# "Those are my family names: Miguel Manuel" +templating::replace_var () { + local any + if (( $# % 2 == 0 )); then + any="$( [value1 [... [valueN]] +# +# echo "Those are common names in spain: XXX_NAMES_XXX" |\ +# templating::replace_var_join names ', ' Manuel Jorge David Luis Pedro +# +# This will print: +# "Those are common names in spain: Manuel, Jorge, David, Luis, Pedro" +# +templating::replace_var_join() { + local input="$(" --name=Gabriel --email-address=no-email@example.com +# templating::replace "XXX_NAME_XXX " --name Gabriel --email-address no-email@example.com +# templating::replace "XXX_NAME_XXX " name Gabriel email-address no-email@example.com +# echo "XXX_NAME_XXX " |\ +# templating::replace name Gabriel email-address no-email@example.com +# +# This will print +# "Gabriel " +# +templating::replace() { + local var_name var_value output + case "$1" in + --*=*|--*) + output=$( "$file" +} \ No newline at end of file diff --git a/scripts/dotfiles/create b/scripts/dotfiles/create index f7033018d..b5d186bb3 100755 --- a/scripts/dotfiles/create +++ b/scripts/dotfiles/create @@ -3,18 +3,30 @@ set -euo pipefail source "$DOTLY_PATH/scripts/core/_main.sh" +source "$DOTLY_PATH/scripts/core/templating.sh" ##? Create the dotfiles structure ##? ##? Usage: -##? create [dotfiles_path] +##? test ##? docs::parse "$@" dotfiles::apply_templating() { - sed -i -e "s|XXX_DOTFILES_PATH_XXX|$DOTFILES_PATH|g" "$DOTFILES_PATH/bin/sdot" - sed -i -e "s|XXX_DOTFILES_PATH_XXX|$DOTFILES_PATH|g" "$DOTFILES_PATH/shell/bash/.bashrc" - sed -i -e "s|XXX_DOTFILES_PATH_XXX|$DOTFILES_PATH|g" "$DOTFILES_PATH/shell/zsh/.zshenv" + # Old template files + # local tpl_files=( + # "$DOTFILES_PATH/bin/sdot" + # "$DOTFILES_PATH/shell/bash/.bashrc" + # "$DOTFILES_PATH/shell/zsh/.zshenv" + # ) + local tpl_files=( + "$DOTFILES_PATH/bin/sdot" + "$DOTFILES_PATH/shell/dotly-vars.sh" + ) + + for file in "$tpl_files"; do + templating::file "$file" --dotfiles-path="$DOTFILES_PATH" + done } if [ ! -d "$DOTFILES_PATH/shell" ]; then @@ -25,4 +37,4 @@ if [ ! -d "$DOTFILES_PATH/shell" ]; then log::success "Done!" else log::note "dotfiles already created, ignoring" -fi +fi \ No newline at end of file diff --git a/scripts/self/init b/scripts/self/init new file mode 100755 index 000000000..ed532af52 --- /dev/null +++ b/scripts/self/init @@ -0,0 +1,120 @@ +#!/usr/bin/env bash + +source "$DOTLY_PATH/scripts/core/_main.sh" +source "$DOTLY_PATH/scripts/self/utils/init.sh" + +##? Enable/Disable init scripts +##? +##? +##? Usage: +##? init [-h | --help] +##? init [-v | --version] +##? init enable [] +##? init disable [] +##? init status [] +##? +##? Options: +##? -h --help Show this help +##? -v --version Show the program version +##? +##? Author: +##? Gabriel Trabanco Llano + +# Options part its important because assign short and long version of the params +docs::parse "$@" + +SCRIPT_NAME="dot self autoupdater" +SCRIPT_VERSION="1.0.0" + +# Print name and version +if $version; then + output::write "$SCRIPT_NAME v$SCRIPT_VERSION" + exit +fi + +# Create folders if they does not exists +mkdir -p "$DOTLY_INIT_SCRIPTS_PATH" +mkdir -p "$DOTFILES_INIT_SCRIPTS_PATH" +mkdir -p "$ENABLED_INIT_SCRIPTS_PATH" + +[[ ! -d "$ENABLED_INIT_SCRIPTS_PATH" ]] && output::error "The folder path to enable scripts does not exists" && exit 1 +[[ ! -d "$DOTLY_INIT_SCRIPTS_PATH" ]] && output::error "The init scripts of DOTLY does not exists" && exit 1 + +# Get the scripts +init_scripts=("$(init::get_scripts)") +enabled_scripts=("$(init::get_enabled)") + +case $1 in +"enable") + if [[ -n "$script_name" ]]; then + if init::exists_script "$script_name"; then + init::enable "$script_name" + init::status "$script_name" && output::solution "Enabled" && exit 0 + output::error "Could not be enabled." && exit 1 + else + output::error "$script_name does not exists." + exit 1 + fi + fi + + not_enabled_scripts=("$(output::array_disjunction "${init_scripts[@]}" "${enabled_scripts[@]}")") + [[ -n "$not_enabled_scripts" ]] && to_enable=$(output::array_disjunction "${init_scripts[@]}" "${enabled_scripts[@]}" | init::fzf "Choose one or more (Shift + Tab) scripts to enable when init terminal") || output::answer "Nothing can be enabled" + [[ -z "$to_enable" ]] && exit 0 + + for item in "${to_enable[@]}"; do + output::answer "Init script '$item'..." + init::enable "$item" + if init::status "$item"; then + output::solution "Enabled" + else + output::error "Could not be enabled." + exit 1 + fi + done + ;; +"disable") + if [[ -n "$script_name" ]]; then + if init::exists_script "$script_name"; then + init::disable "$script_name" + if ! init::status "$script_name"; then + output::solution "Disabled" && exit 0 + fi + + output::error "Could not be disabled." && exit 1 + else + output::error "$script_name does not exists." + exit 1 + fi + fi + + [[ -n "$enabled_scripts" ]] && to_disable=$(echo "${enabled_scripts[@]}" | init::fzf "Choose one or more (Shift + Tab) scripts to disable from init terminal") || output::answer "Nothing to be disabled" + [[ -z "$to_disable" ]] && exit 0 + + init::disable "${to_disable[@]}" + for item in "${to_disable[@]}"; do + output::answer "Init script '$item'..." + + if ! init::status "$item"; then + output::solution "Disabled" + else + output::error "Could not be disabled." + fi + done + ;; +"status") + if [ ! -z "$script_name" ]; then + init::status "$script_name" && output::solution "'$script_name' is enabled" || output::error "'$script_name' is disabled" + else + for item in "${init_scripts[@]}"; do + init::status "$item" &&\ + output::solution "'$item'... Enabled." ||\ + output::error "'$item'... Disabled." + done + fi + ;; +*) + "$DOTLY_PATH/bin/dot" self init -h + ;; +esac + +exit 0 \ No newline at end of file diff --git a/scripts/self/utils/init.sh b/scripts/self/utils/init.sh new file mode 100644 index 000000000..1e353a263 --- /dev/null +++ b/scripts/self/utils/init.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +# Needed variables +DOTLY_INIT_SCRIPTS_PATH=${DOTLY_INIT_SCRIPTS_PATH:-$DOTLY_PATH/shell/init-scripts} +DOTFILES_INIT_SCRIPTS_PATH=${DOTFILES_INIT_SCRIPTS_PATH:-$DOTFILES_PATH/shell/init-scripts} +ENABLED_INIT_SCRIPTS_PATH=${ENABLED_INIT_SCRIPTS_PATH:-$DOTFILES_PATH/shell/init-scripts.enabled} + +# check if init script is enabled or disabled +init::status() { + [[ -f "$ENABLED_INIT_SCRIPTS_PATH/$1" ]] +} + +# Check if init script exists in dotly or dotfiles +init::exists_script() { + [[ -f "$DOTLY_INIT_SCRIPTS_PATH/$1" ]] || [[ -f "$DOTFILES_INIT_SCRIPTS_PATH" ]] +} + +# Stored init scripts +init::get_scripts() { + [[ -d "$DOTLY_INIT_SCRIPTS_PATH" ]] &&\ + [[ -d "$DOTFILES_INIT_SCRIPTS_PATH" ]] &&\ + find "$DOTLY_INIT_SCRIPTS_PATH" \ + "$DOTFILES_INIT_SCRIPTS_PATH" -name "*" -type f |\ + xargs -I _ basename _ | sort | uniq +} + +# Enabled init scripts +init::get_enabled() { + [[ -d "$ENABLED_INIT_SCRIPTS_PATH" ]] &&\ + find "$ENABLED_INIT_SCRIPTS_PATH" -name "*" -type l |\ + xargs -I _ basename _ | sort | uniq +} + +init::fzf() { + local piped_values="$( Date: Sun, 28 Mar 2021 13:37:14 +0200 Subject: [PATCH 03/54] Improved output::join with a stackoverflow function in: https://stackoverflow.com/a/17841619 --- scripts/core/output.sh | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/scripts/core/output.sh b/scripts/core/output.sh index 92620efe3..424711a88 100644 --- a/scripts/core/output.sh +++ b/scripts/core/output.sh @@ -51,21 +51,10 @@ output::yesno() { output::empty_line() { echo ''; } output::header() { output::empty_line; output::write "${bold_blue}---- $1 ----${normal}"; } output::str_to_upper() { echo $@ | tr '[:lower:]' '[:upper:]'; } -# This only joins by one char as glue -#output::join() { local IFS="$1"; shift; echo "$*"; unset IFS; } # split is not compatible with strings that have new space output::split() { local IFS="$1"; shift; echo "${!@[@]}"; unset IFS; } -#This can join with string as glue -output::join() { - local glue="$1"; shift - local counter=0 - local IFS='' - for item in "$@"; do - counter=$(( $counter + 1 )) - echo -n -e "$item" - [[ $counter -ne $# ]] && echo -n -e "$glue" - done -} +# output::join: https://stackoverflow.com/a/17841619 +output::join() { local glue="$1"; local first="$2"; shift 2; printf "%s" "$2" "${@/#/$glue}"; } # Usage: output::array_* "${arr1[@]}" "${arr2[@]}" output::array_union() { echo "${@}" | tr ' ' '\n' | sort | uniq; } output::array_disjunction() { echo "${@}" | tr ' ' '\n' | sort | uniq -u; } From addcdbb655b0d9e3219d0efac6a9f50a1a33f902 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Sun, 28 Mar 2021 14:33:15 +0200 Subject: [PATCH 04/54] Deleted duplicate functions that were in str.sh and output. Added array.sh. Rename autoupdater_loaded to dotly_autoupdater. --- scripts/core/_main.sh | 2 +- scripts/core/array.sh | 6 +++ scripts/core/output.sh | 9 +--- scripts/core/str.sh | 2 + scripts/self/init | 49 ++++++++++++++----- scripts/self/utils/init.sh | 10 ++-- .../{autoupdate_loader => dotly_autoupdater} | 0 7 files changed, 53 insertions(+), 25 deletions(-) create mode 100644 scripts/core/array.sh rename shell/init-scripts/{autoupdate_loader => dotly_autoupdater} (100%) diff --git a/scripts/core/_main.sh b/scripts/core/_main.sh index 523e177da..2d1e3ffb8 100755 --- a/scripts/core/_main.sh +++ b/scripts/core/_main.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash if ! ${DOT_MAIN_SOURCED:-false}; then - for file in $DOTLY_PATH/scripts/core/{args,collections,documentation,dot,files,git,log,platform,output,str}.sh; do + for file in $DOTLY_PATH/scripts/core/{args,array,collections,documentation,dot,files,git,log,platform,output,str}.sh; do source "$file"; done; unset file; diff --git a/scripts/core/array.sh b/scripts/core/array.sh new file mode 100644 index 000000000..07d4e6dff --- /dev/null +++ b/scripts/core/array.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# Usage: array::* "${arr1[@]}" "${arr2[@]}" +array::union() { echo "${@}" | tr ' ' '\n' | sort | uniq; } +array::disjunction() { echo "${@}" | tr ' ' '\n' | sort | uniq -u; } +array::difference() { echo "${@}" | tr ' ' '\n' | sort | uniq -d; } \ No newline at end of file diff --git a/scripts/core/output.sh b/scripts/core/output.sh index 424711a88..09edd9e35 100644 --- a/scripts/core/output.sh +++ b/scripts/core/output.sh @@ -50,12 +50,5 @@ output::yesno() { } output::empty_line() { echo ''; } output::header() { output::empty_line; output::write "${bold_blue}---- $1 ----${normal}"; } -output::str_to_upper() { echo $@ | tr '[:lower:]' '[:upper:]'; } -# split is not compatible with strings that have new space -output::split() { local IFS="$1"; shift; echo "${!@[@]}"; unset IFS; } # output::join: https://stackoverflow.com/a/17841619 -output::join() { local glue="$1"; local first="$2"; shift 2; printf "%s" "$2" "${@/#/$glue}"; } -# Usage: output::array_* "${arr1[@]}" "${arr2[@]}" -output::array_union() { echo "${@}" | tr ' ' '\n' | sort | uniq; } -output::array_disjunction() { echo "${@}" | tr ' ' '\n' | sort | uniq -u; } -output::array_difference() { echo "${@}" | tr ' ' '\n' | sort | uniq -d; } \ No newline at end of file +output::join() { local glue="$1"; local first="$2"; shift 2; printf "%s" "$2" "${@/#/$glue}"; } \ No newline at end of file diff --git a/scripts/core/str.sh b/scripts/core/str.sh index 18891e25c..7f961e503 100755 --- a/scripts/core/str.sh +++ b/scripts/core/str.sh @@ -10,3 +10,5 @@ str::split() { str::contains() { [[ $2 == *$1* ]] } + +str::to_upper() { echo "$@" | tr '[:lower:]' '[:upper:]'; } \ No newline at end of file diff --git a/scripts/self/init b/scripts/self/init index ed532af52..d4638290f 100755 --- a/scripts/self/init +++ b/scripts/self/init @@ -46,19 +46,29 @@ enabled_scripts=("$(init::get_enabled)") case $1 in "enable") + # If the user gives the script_name if [[ -n "$script_name" ]]; then + status=0 if init::exists_script "$script_name"; then init::enable "$script_name" - init::status "$script_name" && output::solution "Enabled" && exit 0 - output::error "Could not be enabled." && exit 1 + init::status "$script_name" && output::solution "Enabled" + output::error "Could not be enabled." && status=1 else output::error "$script_name does not exists." - exit 1 + status=1 fi + exit $status fi - not_enabled_scripts=("$(output::array_disjunction "${init_scripts[@]}" "${enabled_scripts[@]}")") - [[ -n "$not_enabled_scripts" ]] && to_enable=$(output::array_disjunction "${init_scripts[@]}" "${enabled_scripts[@]}" | init::fzf "Choose one or more (Shift + Tab) scripts to enable when init terminal") || output::answer "Nothing can be enabled" + # If there is no script_name + # If there is nothing that can be enabled or not select scripts to + # be enabled, exit + not_enabled_scripts=("$(array::disjunction "${init_scripts[@]}" "${enabled_scripts[@]}")") + if [[ -n "$not_enabled_scripts" ]]; then + to_enable=$(array::disjunction "${init_scripts[@]}" "${enabled_scripts[@]}" | init::fzf "Choose one or more (Shift + Tab) scripts to enable when init terminal") + else + output::answer "Nothing can be enabled" + fi [[ -z "$to_enable" ]] && exit 0 for item in "${to_enable[@]}"; do @@ -73,21 +83,31 @@ case $1 in done ;; "disable") + # If there is script_name if [[ -n "$script_name" ]]; then + status=0 if init::exists_script "$script_name"; then init::disable "$script_name" if ! init::status "$script_name"; then - output::solution "Disabled" && exit 0 + output::solution "Disabled" fi - output::error "Could not be disabled." && exit 1 + output::error "Could not be disabled." && status=1 else output::error "$script_name does not exists." - exit 1 + status=1 fi + + exit $status fi - [[ -n "$enabled_scripts" ]] && to_disable=$(echo "${enabled_scripts[@]}" | init::fzf "Choose one or more (Shift + Tab) scripts to disable from init terminal") || output::answer "Nothing to be disabled" + # If there is no script_name + # If there are no enabled scripts or nothing to be disabled, exit + if [[ -n "$enabled_scripts" ]]; then + to_disable=$(echo "${enabled_scripts[@]}" | init::fzf "Choose one or more (Shift + Tab) scripts to disable from init terminal") + else + output::answer "Nothing to be disabled" + fi [[ -z "$to_disable" ]] && exit 0 init::disable "${to_disable[@]}" @@ -102,9 +122,15 @@ case $1 in done ;; "status") - if [ ! -z "$script_name" ]; then - init::status "$script_name" && output::solution "'$script_name' is enabled" || output::error "'$script_name' is disabled" + # Check status, if user gives a script_name + if [ -n "$script_name" ]; then + if init::status "$script_name"; then + output::solution "'$script_name' is enabled" + else + output::error "'$script_name' is disabled" + fi else + # If there is no script_name, gives the status of all for item in "${init_scripts[@]}"; do init::status "$item" &&\ output::solution "'$item'... Enabled." ||\ @@ -113,6 +139,7 @@ case $1 in fi ;; *) + # Gives help "$DOTLY_PATH/bin/dot" self init -h ;; esac diff --git a/scripts/self/utils/init.sh b/scripts/self/utils/init.sh index 1e353a263..50f51fc9e 100644 --- a/scripts/self/utils/init.sh +++ b/scripts/self/utils/init.sh @@ -5,16 +5,16 @@ DOTLY_INIT_SCRIPTS_PATH=${DOTLY_INIT_SCRIPTS_PATH:-$DOTLY_PATH/shell/init-script DOTFILES_INIT_SCRIPTS_PATH=${DOTFILES_INIT_SCRIPTS_PATH:-$DOTFILES_PATH/shell/init-scripts} ENABLED_INIT_SCRIPTS_PATH=${ENABLED_INIT_SCRIPTS_PATH:-$DOTFILES_PATH/shell/init-scripts.enabled} -# check if init script is enabled or disabled -init::status() { - [[ -f "$ENABLED_INIT_SCRIPTS_PATH/$1" ]] -} - # Check if init script exists in dotly or dotfiles init::exists_script() { [[ -f "$DOTLY_INIT_SCRIPTS_PATH/$1" ]] || [[ -f "$DOTFILES_INIT_SCRIPTS_PATH" ]] } +# check if init script is enabled or disabled +init::status() { + init::exists_script "$1" && [[ -f "$ENABLED_INIT_SCRIPTS_PATH/$1" ]] +} + # Stored init scripts init::get_scripts() { [[ -d "$DOTLY_INIT_SCRIPTS_PATH" ]] &&\ diff --git a/shell/init-scripts/autoupdate_loader b/shell/init-scripts/dotly_autoupdater similarity index 100% rename from shell/init-scripts/autoupdate_loader rename to shell/init-scripts/dotly_autoupdater From db3a6b9951820f84a1a4d93b814d5725aaef0fc1 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Sun, 28 Mar 2021 16:13:44 +0200 Subject: [PATCH 05/54] Added closed and unapproved PR #61 because it is needed when I use beta branch for testing and developing. --- scripts/self/update | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/self/update b/scripts/self/update index ac8a0ed97..880aa3fb7 100755 --- a/scripts/self/update +++ b/scripts/self/update @@ -10,9 +10,12 @@ source "$DOTLY_PATH/scripts/core/_main.sh" ##? update docs::parse "$@" +cd "$DOTFILES_PATH" +branch=$(git config -f .gitmodules submodule.modules/dotly.branch) + cd "$DOTLY_PATH" git discard >/dev/null 2>&1 -git checkout master >/dev/null 2>&1 +git checkout "$branch" >/dev/null 2>&1 git pull >/dev/null 2>&1 git submodule update --init --recursive > /dev/null 2>&1 From 4e744a794fb4a338af28c3b69fded21cd1b0b483 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Sun, 28 Mar 2021 16:28:41 +0200 Subject: [PATCH 06/54] Fixed error that all the the time say that script_name where not dis/enabled when was passed as argument --- scripts/self/init | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/self/init b/scripts/self/init index d4638290f..31105604f 100755 --- a/scripts/self/init +++ b/scripts/self/init @@ -52,7 +52,7 @@ case $1 in if init::exists_script "$script_name"; then init::enable "$script_name" init::status "$script_name" && output::solution "Enabled" - output::error "Could not be enabled." && status=1 + ! init::status "$script_name" && output::error "Could not be enabled." && status=1 else output::error "$script_name does not exists." status=1 @@ -92,7 +92,7 @@ case $1 in output::solution "Disabled" fi - output::error "Could not be disabled." && status=1 + init::status "$script_name" && output::error "Could not be disabled." && status=1 else output::error "$script_name does not exists." status=1 From 6fd93490ee5762516dd7994c99bd2c1c26440172 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Sun, 28 Mar 2021 23:43:35 +0200 Subject: [PATCH 07/54] Fixed the use of refactored function changed to str.sh. Changed output::join to str::join --- scripts/core/output.sh | 4 +--- scripts/core/str.sh | 5 ++++- scripts/core/templating.sh | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/core/output.sh b/scripts/core/output.sh index 09edd9e35..bb922b0e0 100644 --- a/scripts/core/output.sh +++ b/scripts/core/output.sh @@ -49,6 +49,4 @@ output::yesno() { [[ "$PROMPT_REPLY" =~ ^[$default_check] ]] } output::empty_line() { echo ''; } -output::header() { output::empty_line; output::write "${bold_blue}---- $1 ----${normal}"; } -# output::join: https://stackoverflow.com/a/17841619 -output::join() { local glue="$1"; local first="$2"; shift 2; printf "%s" "$2" "${@/#/$glue}"; } \ No newline at end of file +output::header() { output::empty_line; output::write "${bold_blue}---- $1 ----${normal}"; } \ No newline at end of file diff --git a/scripts/core/str.sh b/scripts/core/str.sh index 7f961e503..8e2352599 100755 --- a/scripts/core/str.sh +++ b/scripts/core/str.sh @@ -11,4 +11,7 @@ str::contains() { [[ $2 == *$1* ]] } -str::to_upper() { echo "$@" | tr '[:lower:]' '[:upper:]'; } \ No newline at end of file +str::to_upper() { echo "$@" | tr '[:lower:]' '[:upper:]'; } + +# output::join: https://stackoverflow.com/a/17841619 +str::join() { local glue="$1"; local first="$2"; shift 2; printf "%s" "$2" "${@/#/$glue}"; } \ No newline at end of file diff --git a/scripts/core/templating.sh b/scripts/core/templating.sh index 7f23dd685..245abf664 100755 --- a/scripts/core/templating.sh +++ b/scripts/core/templating.sh @@ -23,7 +23,7 @@ templating::replace_var () { any="$1"; shift fi - local var_name="XXX_$(output::str_to_upper $1 | tr '-' '_')_XXX"; shift + local var_name="XXX_$(str::to_upper $1 | tr '-' '_')_XXX"; shift local values=($@); shift # Replacer @@ -48,7 +48,7 @@ templating::replace_var_join() { local input="$( Date: Mon, 29 Mar 2021 00:41:58 +0200 Subject: [PATCH 08/54] Added missing autoupdate command for docpars --- bin/dotly | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/dotly b/bin/dotly index 3f297a641..ef735432f 100755 --- a/bin/dotly +++ b/bin/dotly @@ -6,6 +6,7 @@ source "$DOTLY_PATH/scripts/core/_main.sh" ##? Usage: ##? dotly self-update +##? dotly autoupdate docs::parse "$@" case $1 in From 145a56cc9946d0f293dadf74dff97a18e291d988 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Mon, 29 Mar 2021 00:55:47 +0200 Subject: [PATCH 09/54] Fixed all the mess with loader and vars --- dotfiles_template/shell/bash/.bashrc | 42 +-------------------------- dotfiles_template/shell/dotly-vars.sh | 3 -- dotfiles_template/shell/zsh/.zshrc | 26 +---------------- scripts/dotfiles/create | 9 ++---- 4 files changed, 4 insertions(+), 76 deletions(-) delete mode 100755 dotfiles_template/shell/dotly-vars.sh diff --git a/dotfiles_template/shell/bash/.bashrc b/dotfiles_template/shell/bash/.bashrc index 9a3bcfcad..e498615d9 100644 --- a/dotfiles_template/shell/bash/.bashrc +++ b/dotfiles_template/shell/bash/.bashrc @@ -2,44 +2,4 @@ export DOTFILES_PATH="XXX_DOTFILES_PATH_XXX" export DOTLY_PATH="$DOTFILES_PATH/modules/dotly" export DOTLY_THEME="codely" -if [[ "$(ps -p $$ -ocomm=)" =~ (bash$) ]]; then - __right_prompt() { - RIGHT_PROMPT="" - [[ -n $RPS1 ]] && RIGHT_PROMPT=$RPS1 || RIGHT_PROMPT=$RPROMPT - if [[ -n $RIGHT_PROMPT ]]; then - n=$(($COLUMNS - ${#RIGHT_PROMPT})) - printf "%${n}s$RIGHT_PROMPT\\r" - fi - } - export PROMPT_COMMAND="__right_prompt" -fi - -source "$DOTFILES_PATH/shell/paths.sh" - -PATH=$( - IFS=":" - echo "${path[*]}" -) -export PATH - -source "$DOTFILES_PATH/shell/init.sh" - -themes_paths=( - "$DOTFILES_PATH/shell/bash/themes" - "$DOTLY_PATH/shell/bash/themes" -) - -for THEME_PATH in ${themes_paths[@]}; do - THEME_PATH="${THEME_PATH}/$DOTLY_THEME.sh" - [ -f "$THEME_PATH" ] && source "$THEME_PATH" && break -done - -for bash_file in "$DOTLY_PATH"/shell/bash/completions/*; do - source "$bash_file" -done - -if [ -n "$(ls -A "$DOTFILES_PATH/shell/bash/completions/")" ]; then - for bash_file in "$DOTFILES_PATH"/shell/bash/completions/*; do - source "$bash_file" - done -fi +[[ -f "$DOTLY_PATH/shell/bash/init-dotly.sh" ]] && "$DOTLY_PATH/shell/bash/init-dotly.sh" || echo "\033[0;31m\033[1mDOTLY Could not be loaded\033[0m" \ No newline at end of file diff --git a/dotfiles_template/shell/dotly-vars.sh b/dotfiles_template/shell/dotly-vars.sh deleted file mode 100755 index 79d257a49..000000000 --- a/dotfiles_template/shell/dotly-vars.sh +++ /dev/null @@ -1,3 +0,0 @@ -export DOTFILES_PATH="XXX_DOTFILES_PATH_XXX" -export DOTLY_PATH="$DOTFILES_PATH/modules/dotly" -export DOTLY_THEME="codely" \ No newline at end of file diff --git a/dotfiles_template/shell/zsh/.zshrc b/dotfiles_template/shell/zsh/.zshrc index 4f96e2ae0..036b1d60a 100644 --- a/dotfiles_template/shell/zsh/.zshrc +++ b/dotfiles_template/shell/zsh/.zshrc @@ -1,28 +1,4 @@ # Uncomment for debuf with `zprof` # zmodload zsh/zprof -# Firstly Paths -source "$DOTFILES_PATH/shell/paths.sh" - -# ZSH Ops -setopt HIST_IGNORE_ALL_DUPS -setopt HIST_FCNTL_LOCK -setopt +o nomatch -# setopt autopushd - -# Start zim -source "$ZIM_HOME/init.zsh" - -# Async mode for autocompletion -ZSH_AUTOSUGGEST_USE_ASYNC=true -ZSH_HIGHLIGHT_MAXLENGTH=300 - -source "$DOTFILES_PATH/shell/init.sh" - -fpath=("$DOTFILES_PATH/shell/zsh/themes" "$DOTFILES_PATH/shell/zsh/autocompletions" "$DOTLY_PATH/shell/zsh/themes" "$DOTLY_PATH/shell/zsh/completions" $fpath) - -autoload -Uz promptinit && promptinit -prompt ${DOTLY_THEME:-codely} - -source "$DOTLY_PATH/shell/zsh/bindings/reverse_search.zsh" -source "$DOTFILES_PATH/shell/zsh/key-bindings.zsh" +[[ -f "$DOTLY_PATH/shell/bash/init-dotly.sh" ]] && "$DOTLY_PATH/shell/bash/init-dotly.sh" || echo "\033[0;31m\033[1mDOTLY Could not be loaded\033[0m" diff --git a/scripts/dotfiles/create b/scripts/dotfiles/create index b5d186bb3..52f7b1991 100755 --- a/scripts/dotfiles/create +++ b/scripts/dotfiles/create @@ -13,15 +13,10 @@ source "$DOTLY_PATH/scripts/core/templating.sh" docs::parse "$@" dotfiles::apply_templating() { - # Old template files - # local tpl_files=( - # "$DOTFILES_PATH/bin/sdot" - # "$DOTFILES_PATH/shell/bash/.bashrc" - # "$DOTFILES_PATH/shell/zsh/.zshenv" - # ) local tpl_files=( "$DOTFILES_PATH/bin/sdot" - "$DOTFILES_PATH/shell/dotly-vars.sh" + "$DOTFILES_PATH/shell/bash/.bashrc" + "$DOTFILES_PATH/shell/zsh/.zshenv" ) for file in "$tpl_files"; do From 5802b61a85e6d88bbeb1708f81e78c9ac213a118 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Mon, 29 Mar 2021 02:44:23 +0200 Subject: [PATCH 10/54] Added a way to modify DOTFILES_PATH structure when add a feature to dotly, fixed all the way init-scripts were loaded because they fail. Fixed some issues. --- dotfiles_template/shell/bash/.bashrc | 7 ++- dotfiles_template/shell/zsh/.zshrc | 7 ++- dotfiles_template/symlinks/conf.yaml | 5 +++ scripts/self/init | 6 +-- scripts/symlinks/apply | 64 ++++++++++++++++++++++++---- shell/bash/init-dotly.sh | 16 +++---- shell/zsh/init-dotly.sh | 25 +++++++---- symlinks/core-feature.yaml | 10 +++++ 8 files changed, 109 insertions(+), 31 deletions(-) create mode 100644 symlinks/core-feature.yaml diff --git a/dotfiles_template/shell/bash/.bashrc b/dotfiles_template/shell/bash/.bashrc index e498615d9..de0d19b5d 100644 --- a/dotfiles_template/shell/bash/.bashrc +++ b/dotfiles_template/shell/bash/.bashrc @@ -2,4 +2,9 @@ export DOTFILES_PATH="XXX_DOTFILES_PATH_XXX" export DOTLY_PATH="$DOTFILES_PATH/modules/dotly" export DOTLY_THEME="codely" -[[ -f "$DOTLY_PATH/shell/bash/init-dotly.sh" ]] && "$DOTLY_PATH/shell/bash/init-dotly.sh" || echo "\033[0;31m\033[1mDOTLY Could not be loaded\033[0m" \ No newline at end of file +if [[ -f "$DOTLY_PATH/shell/bash/init-dotly.sh" ]] +then + . "$DOTLY_PATH/shell/bash/init-dotly.sh" +else + echo "\033[0;31m\033[1mDOTLY Could not be loaded\033[0m" +fi \ No newline at end of file diff --git a/dotfiles_template/shell/zsh/.zshrc b/dotfiles_template/shell/zsh/.zshrc index 036b1d60a..a6872284a 100644 --- a/dotfiles_template/shell/zsh/.zshrc +++ b/dotfiles_template/shell/zsh/.zshrc @@ -1,4 +1,9 @@ # Uncomment for debuf with `zprof` # zmodload zsh/zprof -[[ -f "$DOTLY_PATH/shell/bash/init-dotly.sh" ]] && "$DOTLY_PATH/shell/bash/init-dotly.sh" || echo "\033[0;31m\033[1mDOTLY Could not be loaded\033[0m" +if [[ -f "$DOTLY_PATH/shell/bash/init-dotly.sh" ]] +then + . "$DOTLY_PATH/shell/bash/init-dotly.sh" +else + echo "\033[0;31m\033[1mDOTLY Could not be loaded\033[0m" +fi \ No newline at end of file diff --git a/dotfiles_template/symlinks/conf.yaml b/dotfiles_template/symlinks/conf.yaml index 728b7b318..865b6e66a 100644 --- a/dotfiles_template/symlinks/conf.yaml +++ b/dotfiles_template/symlinks/conf.yaml @@ -5,6 +5,11 @@ create: true force: true +- create: + - $DOTLY_PATH/shell/init-scripts + - $DOTFILES_PATH/shell/init-scripts + - $DOTFILES_PATH/shell/init-scripts.enabled + - link: ~/.bash_profile: shell/bash/.bash_profile ~/.bashrc: shell/bash/.bashrc diff --git a/scripts/self/init b/scripts/self/init index 31105604f..e20ce20c1 100755 --- a/scripts/self/init +++ b/scripts/self/init @@ -33,9 +33,9 @@ if $version; then fi # Create folders if they does not exists -mkdir -p "$DOTLY_INIT_SCRIPTS_PATH" -mkdir -p "$DOTFILES_INIT_SCRIPTS_PATH" -mkdir -p "$ENABLED_INIT_SCRIPTS_PATH" +# mkdir -p "$DOTLY_INIT_SCRIPTS_PATH" +# mkdir -p "$DOTFILES_INIT_SCRIPTS_PATH" +# mkdir -p "$ENABLED_INIT_SCRIPTS_PATH" [[ ! -d "$ENABLED_INIT_SCRIPTS_PATH" ]] && output::error "The folder path to enable scripts does not exists" && exit 1 [[ ! -d "$DOTLY_INIT_SCRIPTS_PATH" ]] && output::error "The init scripts of DOTLY does not exists" && exit 1 diff --git a/scripts/symlinks/apply b/scripts/symlinks/apply index 2731cac40..4ef60678a 100755 --- a/scripts/symlinks/apply +++ b/scripts/symlinks/apply @@ -13,23 +13,69 @@ symlinks::apply() { echo } +symlinks::get_files() { + [[ -d "$DOTLY_PATH/symlinks" ]] &&\ + find "$DOTLY_PATH/symlinks" -name "*" -type f |\ + xargs -I _ basename _ | sort +} + +symlinks::fzf() { + local piped_values="$( Date: Mon, 29 Mar 2021 02:55:31 +0200 Subject: [PATCH 11/54] Fixed error when no subcommand were passed --- scripts/symlinks/apply | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/symlinks/apply b/scripts/symlinks/apply index 4ef60678a..f15bac161 100755 --- a/scripts/symlinks/apply +++ b/scripts/symlinks/apply @@ -48,7 +48,7 @@ if $version; then exit fi -case $1 in +case "${1:-}" in "update") symlinks_file="$DOTLY_PATH/symlinks/$(symlinks::get_files | symlinks::fzf)" [[ -z "$symlinks_file" ]] && exit 0 From 639d2449d77c0c0155b338e550b9ba16f5ee65e2 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Mon, 29 Mar 2021 02:56:49 +0200 Subject: [PATCH 12/54] Fixed for non alphanumeric files --- scripts/symlinks/apply | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/symlinks/apply b/scripts/symlinks/apply index f15bac161..db74d71d4 100755 --- a/scripts/symlinks/apply +++ b/scripts/symlinks/apply @@ -15,7 +15,7 @@ symlinks::apply() { symlinks::get_files() { [[ -d "$DOTLY_PATH/symlinks" ]] &&\ - find "$DOTLY_PATH/symlinks" -name "*" -type f |\ + find "$DOTLY_PATH/symlinks" -name "*" -type f -print0 |\ xargs -I _ basename _ | sort } From 7ebb649e93c05093238edaf8a1330bc5c883f479 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Mon, 29 Mar 2021 02:58:23 +0200 Subject: [PATCH 13/54] Fixed for non alphanumeric files. No include . and .. directories. --- shell/bash/init-dotly.sh | 2 +- shell/zsh/init-dotly.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/bash/init-dotly.sh b/shell/bash/init-dotly.sh index 2d457b864..e8c2328e0 100755 --- a/shell/bash/init-dotly.sh +++ b/shell/bash/init-dotly.sh @@ -43,6 +43,6 @@ fi # Auto Init scripts at the end init_scripts_path="$DOTFILES_PATH/shell/init-scripts.enabled" mkdir -p "$init_scripts_path" -find "$init_scripts_path" -mindepth 1 -maxdepth 1 -type f -name '*' -not -path '*/\.*' | while read init_script; do +find "$init_scripts_path" -mindepth 1 -maxdepth 1 -type f -name '*' -not -path '*/\.*' -print0 | grep -v \. | while read init_script; do echo "$init_script" done \ No newline at end of file diff --git a/shell/zsh/init-dotly.sh b/shell/zsh/init-dotly.sh index 889930dcb..097b43230 100755 --- a/shell/zsh/init-dotly.sh +++ b/shell/zsh/init-dotly.sh @@ -34,6 +34,6 @@ prompt ${DOTLY_THEME:-codely} # Auto Init scripts at the end init_scripts_path="$DOTFILES_PATH/shell/init-scripts.enabled" mkdir -p "$init_scripts_path" -find "$init_scripts_path" -mindepth 1 -maxdepth 1 -type f -name '*' | grep -v \. | while read init_script; do +find "$init_scripts_path" -mindepth 1 -maxdepth 1 -type f -name '*' -print0 | grep -v \. | while read init_script; do #[[ -f "$init_script" ]] && . "$init_script" done From f85b4bf5ae289a4140f5f95c80b9dfdcee8bdb19 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Mon, 29 Mar 2021 03:18:56 +0200 Subject: [PATCH 14/54] Now you can apply directly a symlink docbot file if you know the name 'dot symlinks apply update core-feature' --- scripts/self/init | 21 +++++++++------------ scripts/symlinks/apply | 20 ++++++++++++++++---- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/scripts/self/init b/scripts/self/init index e20ce20c1..908864075 100755 --- a/scripts/self/init +++ b/scripts/self/init @@ -33,18 +33,18 @@ if $version; then fi # Create folders if they does not exists -# mkdir -p "$DOTLY_INIT_SCRIPTS_PATH" -# mkdir -p "$DOTFILES_INIT_SCRIPTS_PATH" -# mkdir -p "$ENABLED_INIT_SCRIPTS_PATH" +mkdir -p "$DOTLY_INIT_SCRIPTS_PATH" +mkdir -p "$DOTFILES_INIT_SCRIPTS_PATH" +mkdir -p "$ENABLED_INIT_SCRIPTS_PATH" -[[ ! -d "$ENABLED_INIT_SCRIPTS_PATH" ]] && output::error "The folder path to enable scripts does not exists" && exit 1 -[[ ! -d "$DOTLY_INIT_SCRIPTS_PATH" ]] && output::error "The init scripts of DOTLY does not exists" && exit 1 +[[ ! -d "$ENABLED_INIT_SCRIPTS_PATH" ]] && output::error "The folder path to enable scripts does not exists.\n\tTry with 'dot symlinks apply update core-feature' first." && exit 1 +[[ ! -d "$DOTLY_INIT_SCRIPTS_PATH" ]] && output::error "The init scripts of DOTLY does not exists.\n\tTry with 'dot symlinks apply update core-feature' first." && exit 1 # Get the scripts init_scripts=("$(init::get_scripts)") enabled_scripts=("$(init::get_enabled)") -case $1 in +case "${1:-}" in "enable") # If the user gives the script_name if [[ -n "$script_name" ]]; then @@ -72,12 +72,11 @@ case $1 in [[ -z "$to_enable" ]] && exit 0 for item in "${to_enable[@]}"; do - output::answer "Init script '$item'..." init::enable "$item" if init::status "$item"; then - output::solution "Enabled" + output::solution "Init script '$item'... Enabled" else - output::error "Could not be enabled." + output::error "Init script '$item' error... It could not be enabled." exit 1 fi done @@ -142,6 +141,4 @@ case $1 in # Gives help "$DOTLY_PATH/bin/dot" self init -h ;; -esac - -exit 0 \ No newline at end of file +esac \ No newline at end of file diff --git a/scripts/symlinks/apply b/scripts/symlinks/apply index db74d71d4..d64982407 100755 --- a/scripts/symlinks/apply +++ b/scripts/symlinks/apply @@ -31,7 +31,7 @@ symlinks::fzf() { ##? ##? Usage: ##? apply -##? apply update +##? apply update [] ##? ##? Options: ##? -h --help Show this help @@ -50,8 +50,20 @@ fi case "${1:-}" in "update") - symlinks_file="$DOTLY_PATH/symlinks/$(symlinks::get_files | symlinks::fzf)" - [[ -z "$symlinks_file" ]] && exit 0 + if [[ -z "$symlinks_file" ]]; then + symlinks_file="$DOTLY_PATH/symlinks/$(symlinks::get_files | symlinks::fzf)" + [[ -z "$symlinks_file" ]] && exit 0 + else + if [[ -f "$DOTLY_PATH/symlinks/$symlinks_file.yaml" ]]; then + symlinks_file="$DOTLY_PATH/symlinks/$symlinks_file.yaml" + elif [[ -f "$DOTLY_PATH/symlinks/$symlinks_file" ]]; then + symlinks_file="$DOTLY_PATH/symlinks/$symlinks_file" + else + output::error "The file does not exists" + exit 1 + fi + fi + output::header "Apply dotbot update to your dotfiles" output::write "This will apply a selected symlinks to apply any dotly update" @@ -60,7 +72,7 @@ case "${1:-}" in "$DOTLY_PATH/modules/dotbot/bin/dotbot" -d "$DOTFILES_PATH" -c "$symlinks_file" output::empty_line - output::write "Remember to merge this symlinks file to yours:" + output::write "Remember to merge this symlinks file to yours in:" output::answer "$DOTFILES_PATH/symlinks/conf.yaml" ;; *) From 5f8e96ff0273fda82f1df13fd48f643b1331baed Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Wed, 31 Mar 2021 23:59:59 +0200 Subject: [PATCH 15/54] Fixed output::question in macOS now does not print a newline like in other OS --- scripts/core/output.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/core/output.sh b/scripts/core/output.sh index bb922b0e0..f28291446 100644 --- a/scripts/core/output.sh +++ b/scripts/core/output.sh @@ -18,7 +18,7 @@ output::error() { output::answer "${red}$@${normal}"; } output::solution() { output::answer "${green}$@${normal}"; } output::question() { if [ platform::is_macos ]; then - output::answer "🤔 $1: "; + echo -n " > 🤔 $1: "; read -r "$2"; else read -rp "🤔 $1: " "$2" From 659326ff4122a44a702b4da3da613cdbfb349534 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Thu, 1 Apr 2021 00:00:40 +0200 Subject: [PATCH 16/54] Added new functions to get the current script_name or script_path where the functions were run --- scripts/core/platform.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/core/platform.sh b/scripts/core/platform.sh index ad140eb16..8f657766f 100644 --- a/scripts/core/platform.sh +++ b/scripts/core/platform.sh @@ -60,4 +60,12 @@ platform::semver_compare() { else echo $compare_patch fi +} + +platform::get_script_path() { + echo "$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +} + +platform::get_full_script_path() { + echo "$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )/$(basename $0)" } \ No newline at end of file From 1a6bdb8e0c38a7122898422ee9bf9afa98218472 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Thu, 1 Apr 2021 00:01:02 +0200 Subject: [PATCH 17/54] Added function to conver mayus to lower --- scripts/core/str.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/core/str.sh b/scripts/core/str.sh index 8e2352599..d480aa224 100755 --- a/scripts/core/str.sh +++ b/scripts/core/str.sh @@ -11,7 +11,8 @@ str::contains() { [[ $2 == *$1* ]] } -str::to_upper() { echo "$@" | tr '[:lower:]' '[:upper:]'; } +str::to_upper() { echo "${@:-$( Date: Thu, 1 Apr 2021 00:01:49 +0200 Subject: [PATCH 18/54] Fixed quotation --- scripts/core/platform.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/core/platform.sh b/scripts/core/platform.sh index 8f657766f..6a5ba9e92 100644 --- a/scripts/core/platform.sh +++ b/scripts/core/platform.sh @@ -54,11 +54,11 @@ platform::semver_compare() { compare_patch="$(compare_ver $patch1 $patch2)" if [[ $compare_major -ne 0 ]]; then - echo $compare_major + echo "$compare_major" elif [[ $compare_minor -ne 0 ]]; then - echo $compare_minor + echo "$compare_minor" else - echo $compare_patch + echo "$compare_patch" fi } From 0279d4a7437967bc3f2bc58314c274f8c4f3fbcb Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Date: Thu, 1 Apr 2021 01:24:19 +0200 Subject: [PATCH 19/54] Added ZDOTDIR This seems necessary to avoid `zmodule` errors while loading ZIMFW. --- dotfiles_template/shell/zsh/.zshenv | 1 + 1 file changed, 1 insertion(+) diff --git a/dotfiles_template/shell/zsh/.zshenv b/dotfiles_template/shell/zsh/.zshenv index 3389931f9..5c931b4d3 100644 --- a/dotfiles_template/shell/zsh/.zshenv +++ b/dotfiles_template/shell/zsh/.zshenv @@ -2,3 +2,4 @@ export DOTFILES_PATH="XXX_DOTFILES_PATH_XXX" export DOTLY_PATH="$DOTFILES_PATH/modules/dotly" export DOTLY_THEME="codely" export ZIM_HOME="$DOTLY_PATH/modules/zimfw" +export ZDOTDIR="$ZIM_HOME" From 02a75477d4dbab866be040b2d86a44c168f473f8 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Date: Thu, 1 Apr 2021 01:25:11 +0200 Subject: [PATCH 20/54] Fixed error in path to load zsh loader for DOTLY --- dotfiles_template/shell/zsh/.zshrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dotfiles_template/shell/zsh/.zshrc b/dotfiles_template/shell/zsh/.zshrc index a6872284a..3a69667cb 100644 --- a/dotfiles_template/shell/zsh/.zshrc +++ b/dotfiles_template/shell/zsh/.zshrc @@ -1,9 +1,9 @@ # Uncomment for debuf with `zprof` # zmodload zsh/zprof -if [[ -f "$DOTLY_PATH/shell/bash/init-dotly.sh" ]] +if [[ -f "$DOTLY_PATH/shell/zsh/init-dotly.sh" ]] then - . "$DOTLY_PATH/shell/bash/init-dotly.sh" + . "$DOTLY_PATH/shell/zsh/init-dotly.sh" else echo "\033[0;31m\033[1mDOTLY Could not be loaded\033[0m" -fi \ No newline at end of file +fi From 1fbdc5d41209aa41b5b3b24a382189895c4d13c9 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Date: Thu, 1 Apr 2021 01:27:07 +0200 Subject: [PATCH 21/54] Fixed quotation that made loop array not working --- scripts/dotfiles/create | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/dotfiles/create b/scripts/dotfiles/create index 52f7b1991..a19c78a91 100755 --- a/scripts/dotfiles/create +++ b/scripts/dotfiles/create @@ -19,7 +19,7 @@ dotfiles::apply_templating() { "$DOTFILES_PATH/shell/zsh/.zshenv" ) - for file in "$tpl_files"; do + for file in $tpl_files; do templating::file "$file" --dotfiles-path="$DOTFILES_PATH" done } @@ -32,4 +32,4 @@ if [ ! -d "$DOTFILES_PATH/shell" ]; then log::success "Done!" else log::note "dotfiles already created, ignoring" -fi \ No newline at end of file +fi From d9e058d7beda4d4496185ac4b2642c8893ead0c3 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Date: Thu, 1 Apr 2021 01:46:11 +0200 Subject: [PATCH 22/54] Fix error Fix unbound variable if DOTLY_ENV is not defined due to `set -u` used in scripts --- scripts/self/utils/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/self/utils/install.sh b/scripts/self/utils/install.sh index 619d3ca27..a7591c37e 100755 --- a/scripts/self/utils/install.sh +++ b/scripts/self/utils/install.sh @@ -4,7 +4,7 @@ install_macos_custom() { if ! platform::command_exists brew; then output::error "brew not installed, installing" - if [ "$DOTLY_ENV" == "CI" ]; then + if [ "${DOTLY_ENV:-}" == "CI" ]; then export CI=1 fi From b4f2dec04d71c9f681eeeea8836dfae3214477ae Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Date: Thu, 1 Apr 2021 02:16:58 +0200 Subject: [PATCH 23/54] Reverting changes --- dotfiles_template/shell/zsh/.zshenv | 1 - 1 file changed, 1 deletion(-) diff --git a/dotfiles_template/shell/zsh/.zshenv b/dotfiles_template/shell/zsh/.zshenv index 5c931b4d3..3389931f9 100644 --- a/dotfiles_template/shell/zsh/.zshenv +++ b/dotfiles_template/shell/zsh/.zshenv @@ -2,4 +2,3 @@ export DOTFILES_PATH="XXX_DOTFILES_PATH_XXX" export DOTLY_PATH="$DOTFILES_PATH/modules/dotly" export DOTLY_THEME="codely" export ZIM_HOME="$DOTLY_PATH/modules/zimfw" -export ZDOTDIR="$ZIM_HOME" From 5902a6f288bbfd2b99f043c892e85d33be580fd3 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Thu, 1 Apr 2021 17:14:13 +0200 Subject: [PATCH 24/54] Fixed error with array. Modified templating so now replace directly in the file if you gives a file to any variable --- scripts/core/templating.sh | 56 ++++++++++++++++++-------------------- scripts/dotfiles/create | 4 +-- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/scripts/core/templating.sh b/scripts/core/templating.sh index 245abf664..e1477407b 100755 --- a/scripts/core/templating.sh +++ b/scripts/core/templating.sh @@ -6,7 +6,6 @@ # Author: Gabriel Trabanco # This was done, using "dot dotfiles create" as reference - # templating::replace_var [|] [value1 [... [valueN]] # echo "template string" | templating::replace_var [value1 [... [valueN]] # @@ -23,14 +22,16 @@ templating::replace_var () { any="$1"; shift fi - local var_name="XXX_$(str::to_upper $1 | tr '-' '_')_XXX"; shift - local values=($@); shift + local var_name="XXX_$(str::to_upper "$1" | tr '-' '_')_XXX"; shift + local value="$1"; shift # Replacer if [[ -f $any ]]; then - sed -i -e "s|$var_name|$values|g" "$any" + echo "Using sed: $var_name = $value" + sed -i -e "s|${var_name}|${value}|g" "$any" else - echo "$any" | sed -e "s|$var_name|$values|g" + echo "Using var" + echo "${any//$var_name/$value}" fi } @@ -50,7 +51,11 @@ templating::replace_var_join() { local glue="$1"; shift local joined_str="$(str::join "$glue" "$@")" local IFS='' - echo $input | templating::replace_var "$var_name" "$joined_str" + if [[ -f "$input" ]]; then + templating::replace_var "$input" "$var_name" "$joined_str" + else + echo "$input" | templating::replace_var "$var_name" "$joined_str" + fi } # templating::replace "XXX_NAME_XXX " --name=Gabriel --email-address=no-email@example.com @@ -58,6 +63,10 @@ templating::replace_var_join() { # templating::replace "XXX_NAME_XXX " name Gabriel email-address no-email@example.com # echo "XXX_NAME_XXX " |\ # templating::replace name Gabriel email-address no-email@example.com +# templating::replace /path/to/file --name=Gabriel --email-address=no-email@example.com +# templating::replace /path/to/file --name Gabriel --email-address no-email@example.com +# templating::replace /path/to/file name Gabriel email-address no-email@example.com + # # This will print # "Gabriel " @@ -69,11 +78,7 @@ templating::replace() { output=$( "$file" + if [[ -f "$output" ]]; then + cat "$output" + else + echo "$output" + fi } \ No newline at end of file diff --git a/scripts/dotfiles/create b/scripts/dotfiles/create index a19c78a91..c036853a2 100755 --- a/scripts/dotfiles/create +++ b/scripts/dotfiles/create @@ -19,8 +19,8 @@ dotfiles::apply_templating() { "$DOTFILES_PATH/shell/zsh/.zshenv" ) - for file in $tpl_files; do - templating::file "$file" --dotfiles-path="$DOTFILES_PATH" + for file in "${tpl_files[@]}"; do + templating::replace "$file" --dotfiles-path="$DOTFILES_PATH" done } From b5342cf91275bf5530ab71d7f528df5395b89d6c Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Thu, 1 Apr 2021 17:31:21 +0200 Subject: [PATCH 25/54] Added async library --- scripts/core/async.sh | 323 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 323 insertions(+) create mode 100644 scripts/core/async.sh diff --git a/scripts/core/async.sh b/scripts/core/async.sh new file mode 100644 index 000000000..eb5f6f620 --- /dev/null +++ b/scripts/core/async.sh @@ -0,0 +1,323 @@ +#!/usr/bin/env bash + +# This was literally copied from: https://github.com/zombieleet/async-bash + +# This script implements 3 asynchronous function +# setTimeout +# setInterval +# async +# killJob function is not asynchronous + +# check the README.md for information on how to use this script + +declare -a JOB_IDS + +declare -i JOBS=1; + +#source ./functions.sh; + +setTimeout() { + + local command="$1" + local after="$2" + + read -d " " comm <<<"${command}" + + #declare -F $comm &>/dev/null + + local _isDef=$(type -t ${comm}) + + if [[ -z "${_isDef}" ]];then + printf "%s\n" "\"${command}\" is not of type { function, command} " + + return 1; + fi + + + [[ ! $after =~ ^[[:digit:]]+$ ]] && { + printf "%s\n" "require an integer as the second argument but got \"$after\" " + + return 1; + } + + { + sleep ${after} + $command + } & + + JOB_IDS+=( "${JOBS} ${command}" ) + + + + read -d " " -a __kunk__ <<< "${JOB_IDS[$(( ${#JOB_IDS[@]} - 1))]}" + + echo ${__kunk__} + + : $(( JOBS++ )) + +} + +setInterval() { + + local command="$1" + local after="$2" + + read -d " " comm <<<"${command}" + + + + local _isDef=$(type -t ${comm}) + + if [[ -z "${_isDef}" ]];then + printf "%s\n" "\"${command}\" is not of type { function, command} " + + return 1; + fi + + + [[ ! $after =~ ^[[:digit:]]+$ ]] && { + printf "%s\n" "require an integer as the second argument but got \"$after\" " + + return 1; + } + + { + while sleep ${after};do + $command + done + } & + + JOB_IDS+=( "${JOBS} ${command}" ) + + read -d " " -a __kunk__ <<< "${JOB_IDS[$(( ${#JOB_IDS[@]} - 1))]}" + + echo ${__kunk__} + + : $(( JOBS++ )) +} + +killJob() { + + local jobToKill="$1" + local signal="$2" + + signal=${signal^^} + + [[ ! $jobToKill =~ ^[[:digit:]]+$ ]] && { + + printf "%s\n" "\"$jobToKill\" should be an integer "; + + return 1; + } + + + { + [[ -z "$signal" ]] && { + signal="SIGTERM" + } + } || { + # for loop worked better than read line in this case + local __al__signals=$(kill -l); + local isSig=0; + for sig in ${__al__signals};do + + [[ ! $sig =~ ^[[:digit:]]+\)$ ]] && { + [[ $signal == $sig ]] && { + isSig=1; + break; + } + } + done + + (( isSig != 1 )) && { + signal="SIGTERM" + } + + } + + + + for job in ${JOB_IDS[@]};do + + # increment job to 1 since array index starts from 0 + read -d " " -a __kunk__ <<< "${JOB_IDS[$job]}" + + (( __kunk__ == jobToKill )) && { + + + read -d " " -a __kunk__ <<< "${JOB_IDS[$job]}" + + kill -${signal} %${__kunk__} + + local status=$? + + (( status != 0 )) && { + + + printf "cannot kill %s %d\n" "${JOB_IDS[$job]}" "${__kunk__}" + + return 1; + } + + printf "%d killed with %s\n" "${__kunk__}" "${signal}" + + return 0; + } + + done +} + +async() { + + local commandToExec="$1" + local resolve="$2" + local reject="$3" + + [[ -z "$commandToExec" ]] || [[ -z "$reject" ]] || [[ -z "$resolve" ]] && { + printf "%s\n" "Insufficient number of arguments"; + return 1; + } + + + + local __temp=( "$commandToExec" "$reject" "$resolve" ) + + + for _c in "${__temp[@]}";do + + + read -d " " comm <<<"${_c}" + + type "${comm}" &>/dev/null + + local status=$? + + (( status != 0 )) && { + printf "\"%s\" is neither a function nor a recognized command\n" "${_c}"; + unset _c + return 1; + } + + done + + unset __temp ; unset _c + + { + + __result=$($commandToExec) + + status=$? + + (( status == 0 )) && { + $resolve "${__result}" + + } || { + $reject "${status}" + } + unset __result + } & + + + + JOB_IDS+=( "${JOBS} ${command}" ) + + read -d " " -a __kunk__ <<< "${JOB_IDS[$(( ${#JOB_IDS[@]} - 1))]}" + + echo ${__kunk__} + + + : $(( JOBS++ )) + +} + + +parallel() { + + #local funcArray="${@:1:$(( ${#@} - 1 ))}" + + local mainFunc="${1}" + local funcArray="${2}" + local finalFunc="${3}" + + local totalArgs=${#@} + + (( totalArgs < 3 )) && { + printf "%s\n" "Insufficient number of argument" + return 1; + } + + read -d " " __cmd <<<"${mainFunc}" + + local _isDef=$(type -t ${__cmd}) + + + [[ -z $_isDef ]] && { + printf "%s\n" "${__cmd} is not of type { function , alias , builtin or file }" + return 1; + } + + [[ "$(type -t $finalFunc)" != "function" ]] && { + printf "%s\n" "${finalFunc} is not of type { function }" + return 1; + } + + for __arr in ${funcArray};do + + local __isfunc=$(type -t ${__arr}) + + [[ $__isfunc != "function" ]] && { + + printf "%s\n" "${__arr} is not of type { function }" + return 1; + + } + + declare __fArray+=( ${__arr} ) + done + + unset __arr + + { + __result=$($mainFunc) + + status=$? + + (( status != 0 )) && { + $finalFunc "" "${__result}" + return $?; + } + + local _t=0 + + for __async in "${__fArray[@]}";do + + __result=$(${__async} "${__result}") + + status=$? + + (( status != 0 )) && { + $finalFunc "" "${__result}" + + # _t has no use here, since we will be returning from this function + # it was only use for clarity + + _t=1 + return $? + } + + done + + (( _t == 0 )) && { + $finalFunc "${__result}" "" + } + } & + + JOB_IDS+=( "${JOBS} ${command}" ) + + read -d " " -a __kunk__ <<< "${JOB_IDS[$(( ${#JOB_IDS[@]} - 1))]}" + + echo ${__kunk__} + + + : $(( JOBS++ )) +} \ No newline at end of file From e2770cc71e5a806538dd0d7de188c4e3152fa076 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Thu, 1 Apr 2021 17:52:55 +0200 Subject: [PATCH 26/54] Splitted symlinks feature that was added in another different script --- scripts/symlinks/apply | 63 ++++++------------------------------- scripts/symlinks/update | 69 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 54 deletions(-) create mode 100755 scripts/symlinks/update diff --git a/scripts/symlinks/apply b/scripts/symlinks/apply index d64982407..d20d58c0e 100755 --- a/scripts/symlinks/apply +++ b/scripts/symlinks/apply @@ -13,25 +13,10 @@ symlinks::apply() { echo } -symlinks::get_files() { - [[ -d "$DOTLY_PATH/symlinks" ]] &&\ - find "$DOTLY_PATH/symlinks" -name "*" -type f -print0 |\ - xargs -I _ basename _ | sort -} - -symlinks::fzf() { - local piped_values="$(] ##? ##? Options: ##? -h --help Show this help @@ -48,46 +33,16 @@ if $version; then exit fi -case "${1:-}" in -"update") - if [[ -z "$symlinks_file" ]]; then - symlinks_file="$DOTLY_PATH/symlinks/$(symlinks::get_files | symlinks::fzf)" - [[ -z "$symlinks_file" ]] && exit 0 - else - if [[ -f "$DOTLY_PATH/symlinks/$symlinks_file.yaml" ]]; then - symlinks_file="$DOTLY_PATH/symlinks/$symlinks_file.yaml" - elif [[ -f "$DOTLY_PATH/symlinks/$symlinks_file" ]]; then - symlinks_file="$DOTLY_PATH/symlinks/$symlinks_file" - else - output::error "The file does not exists" - exit 1 - fi - fi - - - output::header "Apply dotbot update to your dotfiles" - output::write "This will apply a selected symlinks to apply any dotly update" - - output::empty_line - "$DOTLY_PATH/modules/dotbot/bin/dotbot" -d "$DOTFILES_PATH" -c "$symlinks_file" - output::empty_line +symlinks::apply "conf.yaml" - output::write "Remember to merge this symlinks file to yours in:" - output::answer "$DOTFILES_PATH/symlinks/conf.yaml" - ;; -*) - symlinks::apply "conf.yaml" - - if platform::is_macos; then - if platform::is_macos_arm; then - symlinks::apply "conf.macos.yaml" - else - symlinks::apply "conf.macos-intel.yaml" - fi +if platform::is_macos; then + if platform::is_macos_arm; then + symlinks::apply "conf.macos.yaml" else - symlinks::apply "conf.linux.yaml" + symlinks::apply "conf.macos-intel.yaml" fi +else + symlinks::apply "conf.linux.yaml" +fi - log::success "Done!" - ;; -esac \ No newline at end of file +log::success "Done!" \ No newline at end of file diff --git a/scripts/symlinks/update b/scripts/symlinks/update new file mode 100755 index 000000000..9c1013b83 --- /dev/null +++ b/scripts/symlinks/update @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +set -euo pipefail + +source "$DOTLY_PATH/scripts/core/_main.sh" + +symlinks::get_files() { + [[ -d "$DOTLY_PATH/symlinks" ]] &&\ + find "$DOTLY_PATH/symlinks" -name "*" -type f -print0 |\ + xargs -I _ basename _ | sort +} + +symlinks::fzf() { + local piped_values="$(] +##? +##? Options: +##? -h --help Show this help +##? -v --version Show the program version +##? +docs::parse "$@" + +SCRIPT_NAME="dot symlinks apply" +SCRIPT_VERSION="1.0.0" + +# Print name and version +if $version; then + output::write "$SCRIPT_NAME v$SCRIPT_VERSION" + exit +fi + + +if [[ -z "$symlinks_file" ]]; then + symlinks_file="$DOTLY_PATH/symlinks/$(symlinks::get_files | symlinks::fzf)" + [[ -z "$symlinks_file" ]] && exit 0 +else + if [[ -f "$DOTLY_PATH/symlinks/$symlinks_file.yaml" ]]; then + symlinks_file="$DOTLY_PATH/symlinks/$symlinks_file.yaml" + elif [[ -f "$DOTLY_PATH/symlinks/$symlinks_file" ]]; then + symlinks_file="$DOTLY_PATH/symlinks/$symlinks_file" + else + output::error "The file does not exists" + exit 1 + fi +fi + +if ! output::yesno "This could be danger your current dotfiles. Do you still want to continue"; then + exit 1 +fi + +output::header "Apply dotbot update to your dotfiles" +output::write "This will apply a selected symlinks to apply any dotly update" + +output::empty_line +"$DOTLY_PATH/modules/dotbot/bin/dotbot" -d "$DOTFILES_PATH" -c "$symlinks_file" +output::empty_line + +output::write "Remember to merge this symlinks file to yours in:" +output::answer "$DOTFILES_PATH/symlinks/conf.yaml" + \ No newline at end of file From e5eba9974f00f774c1ef2c1f039378b71f80b52c Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 2 Apr 2021 00:09:35 +0200 Subject: [PATCH 27/54] Load async functions with the all core functionality --- scripts/core/_main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/core/_main.sh b/scripts/core/_main.sh index 2d1e3ffb8..2daad58d3 100755 --- a/scripts/core/_main.sh +++ b/scripts/core/_main.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash if ! ${DOT_MAIN_SOURCED:-false}; then - for file in $DOTLY_PATH/scripts/core/{args,array,collections,documentation,dot,files,git,log,platform,output,str}.sh; do + for file in $DOTLY_PATH/scripts/core/{args,array,async,collections,documentation,dot,files,git,log,platform,output,str}.sh; do source "$file"; done; unset file; From a4c48cfdd395f9191714af4373387176448a0919 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Date: Fri, 2 Apr 2021 02:12:16 +0200 Subject: [PATCH 28/54] Fixed auto init scripts loader --- shell/zsh/init-dotly.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/zsh/init-dotly.sh b/shell/zsh/init-dotly.sh index 097b43230..72de58bc3 100755 --- a/shell/zsh/init-dotly.sh +++ b/shell/zsh/init-dotly.sh @@ -34,6 +34,6 @@ prompt ${DOTLY_THEME:-codely} # Auto Init scripts at the end init_scripts_path="$DOTFILES_PATH/shell/init-scripts.enabled" mkdir -p "$init_scripts_path" -find "$init_scripts_path" -mindepth 1 -maxdepth 1 -type f -name '*' -print0 | grep -v \. | while read init_script; do - #[[ -f "$init_script" ]] && . "$init_script" +find "$init_scripts_path" -mindepth 1 -maxdepth 1 -type f,l -name '*' | while read -r init_script; do + . "$init_script" done From 623262acf4885ca8fb500fac3f6bd865de2be090 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Date: Fri, 2 Apr 2021 02:13:06 +0200 Subject: [PATCH 29/54] Fixed autoload init scripts with bash --- shell/bash/init-dotly.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/bash/init-dotly.sh b/shell/bash/init-dotly.sh index e8c2328e0..6f100326a 100755 --- a/shell/bash/init-dotly.sh +++ b/shell/bash/init-dotly.sh @@ -43,6 +43,6 @@ fi # Auto Init scripts at the end init_scripts_path="$DOTFILES_PATH/shell/init-scripts.enabled" mkdir -p "$init_scripts_path" -find "$init_scripts_path" -mindepth 1 -maxdepth 1 -type f -name '*' -not -path '*/\.*' -print0 | grep -v \. | while read init_script; do +find "$init_scripts_path" -mindepth 1 -maxdepth 1 -type l,f -name '*' | while read init_script; do echo "$init_script" - done \ No newline at end of file + done From ec3772115a7cfeeb778de882942205c41696bbb6 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 2 Apr 2021 03:44:53 +0200 Subject: [PATCH 30/54] Fixed error #93 with bash autocompletions --- shell/bash/init-dotly.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/bash/init-dotly.sh b/shell/bash/init-dotly.sh index e8c2328e0..0850eec88 100755 --- a/shell/bash/init-dotly.sh +++ b/shell/bash/init-dotly.sh @@ -30,12 +30,12 @@ for THEME_PATH in ${themes_paths[@]}; do [ -f "$THEME_PATH" ] && source "$THEME_PATH" && break done -for bash_file in "$DOTLY_PATH"/shell/bash/completions/*; do +for bash_file in "$DOTLY_PATH"/shell/bash/completions/_*; do . "$bash_file" done if [ -n "$(ls -A "$DOTFILES_PATH/shell/bash/completions/")" ]; then - for bash_file in "$DOTFILES_PATH"/shell/bash/completions/*; do + for bash_file in "$DOTFILES_PATH"/shell/bash/completions/_*; do . "$bash_file" done fi @@ -45,4 +45,4 @@ init_scripts_path="$DOTFILES_PATH/shell/init-scripts.enabled" mkdir -p "$init_scripts_path" find "$init_scripts_path" -mindepth 1 -maxdepth 1 -type f -name '*' -not -path '*/\.*' -print0 | grep -v \. | while read init_script; do echo "$init_script" - done \ No newline at end of file + done From ab04c2a351ffa45937038e5e6dfb88949067933a Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 2 Apr 2021 04:08:41 +0200 Subject: [PATCH 31/54] First autouptate version. Help Needed. --- bin/dotly | 44 ---------------------- scripts/self/autoupdate | 20 ++++++++++ scripts/self/update | 2 + scripts/self/utils/autoupdate.sh | 55 ++++++++++++++++++++++++++++ shell/bash/themes/codely.sh | 7 +++- shell/init-scripts/dotly_autoupdater | 3 +- shell/zsh/init-dotly.sh | 6 +-- shell/zsh/themes/prompt_codely_setup | 10 ++++- 8 files changed, 95 insertions(+), 52 deletions(-) create mode 100755 scripts/self/autoupdate create mode 100644 scripts/self/utils/autoupdate.sh diff --git a/bin/dotly b/bin/dotly index ef735432f..76175d76a 100755 --- a/bin/dotly +++ b/bin/dotly @@ -6,56 +6,12 @@ source "$DOTLY_PATH/scripts/core/_main.sh" ##? Usage: ##? dotly self-update -##? dotly autoupdate docs::parse "$@" case $1 in "self-update") dot self update ;; -"autoupdate") - # Variables with default values - DOTLY_AUTO_UPDATE_DAYS=${DOTLY_AUTO_UPDATE_DAYS:-7} - DOTLY_AUTO_UPDATE_MODE=${DOTLY_AUTO_UPDATE_MODE:-reminder} # prompt - - # Other needed variables - CURRENT_DIR="$(pwd)" - - # Change to dotly path - cd "$DOTLY_PATH" - - if [[ $(date -r "$DOTLY_PATH" +%s) -lt $(date -d "now - $DOTLY_AUTO_UPDATE_DAYS days" +%s) ]] &&\ - git diff --quiet "origin/$(git branch --show-current)"; then - - output::empty_line - output::write " -------------------------------------------" - output::write "| 🥳🎉🍾 NEW DOTLY VERSION AVAILABLE 🥳🎉🍾 |" - output::write " -------------------------------------------" - output::empty_line - - case "$DOTLY_AUTO_UPDATE_MODE" in - "auto") - output::answer "🚀 Updating" - dot self update - output::solution "Updated" - ;; - "prompt") - output::yesno "Do you want to update now" &&\ - output::answer "🚀 Updating" &&\ - dot self update &&\ - output::solution "Updated" - ;; - *) - output::write "🚀 To update your current version just type:" - output::answer "dotly self-update" - ;; - esac - - output::empty_line - fi - - cd "$CURRENT_DIR" - ;; *) exit 1 ;; diff --git a/scripts/self/autoupdate b/scripts/self/autoupdate new file mode 100755 index 000000000..447d61114 --- /dev/null +++ b/scripts/self/autoupdate @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -euo pipefail + +source "$DOTLY_PATH/scripts/core/_main.sh" +source "$DOTLY_PATH/scripts/self/utils/autoupdate.sh" + +##? Async autoupdate dotly to avoid load all core functions in default bash +##? +##? Usage: +##? autoupdate +docs::parse "$@" + +DOTLY_AUTO_UPDATE_DAYS=0 +DOTLY_AUTO_UPDATE_MODE="info" # auto, info, prompt + +output::write "Async autoupdater checking for new version..." + +set +eu # Needed to use async +async "autoupdate::updater /Users/gtrabanco/MyCodes/dotly2" autoupdate::success autoupdate::reject \ No newline at end of file diff --git a/scripts/self/update b/scripts/self/update index 880aa3fb7..dbff3eb78 100755 --- a/scripts/self/update +++ b/scripts/self/update @@ -20,3 +20,5 @@ git pull >/dev/null 2>&1 git submodule update --init --recursive > /dev/null 2>&1 output::answer '✅ dotly updated to the latest version' + +rm -f "$DOTFILES_PATH/.dotly_update_available" \ No newline at end of file diff --git a/scripts/self/utils/autoupdate.sh b/scripts/self/utils/autoupdate.sh new file mode 100644 index 000000000..ed492b3c6 --- /dev/null +++ b/scripts/self/utils/autoupdate.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +# DOTLY_AUTO_UPDATE_DAYS=${DOTLY_AUTO_UPDATE_DAYS:-7} +# DOTLY_AUTO_UPDATE_MODE=${DOTLY_AUTO_UPDATE_MODE:-reminder} # prompt +# async "autoupdate::updater '/Users/gtrabanco/MyCodes/dotly2'" autoupdate::success autoupdate::reject + + +autoupdate::updater() { + local CURRENT_DIR GIT_UPDATE_CHECK + + # Other needed variables + CURRENT_DIR="$(pwd)" + GIT_UPDATE_CHECK="${1:-$DOTLY_PATH}" + + # Change to dotly path + cd "$GIT_UPDATE_CHECK" || return 1 + + [[ -f "$DOTFILES_PATH/.dotly_update_available" ]] && return 0 + + if [[ $(date -r "$GIT_UPDATE_CHECK" +%s) -lt $(date -d "now - ${DOTLY_AUTO_UPDATE_DAYS:-7} days" +%s) ]] &&\ + [ "$(git rev-parse HEAD)" != "$(git ls-remote $(git rev-parse --abbrev-ref @{u} | sed 's/\// /g') | cut -f1)" ] + then + touch "$DOTFILES_PATH/.dotly_update_available" + fi + + cd "$CURRENT_DIR" || return 1 +} + +autoupdate::success() { + if [[ -f "$DOTFILES_PATH/.dotly_update_available" ]]; then + case "${DOTLY_AUTO_UPDATE_MODE:-reminder}" in + "auto"|"autoupdate"|"auto-update"|"update") + output::answer "🚀 Updating DOTLY Automatically" + "$DOTLY_PATH/bin/dot" self update + output::solution "Updated, restart your terminal." + rm -f "$DOTFILES_PATH/.dotly_update_available" + ;; + "info") + output::empty_line + output::write " ---------------------------------------------" + output::write "| 🥳🎉🍾 NEW DOTLY VERSION AVAILABLE 🥳🎉🍾 |" + output::write " ---------------------------------------------" + output::empty_line + ;; + *) # prompt or reminder... + # Nothing to do here + ;; + esac + fi +} + +autoupdate::reject() { + # Nothing to be updated + return 0 +} \ No newline at end of file diff --git a/shell/bash/themes/codely.sh b/shell/bash/themes/codely.sh index 2467425b4..d1bb19904 100644 --- a/shell/bash/themes/codely.sh +++ b/shell/bash/themes/codely.sh @@ -8,10 +8,15 @@ codely_theme() { LAST_CODE="$?" current_dir=$(dot core short_pwd) STATUS_COLOR=$GREEN_COLOR + UPDATE_MESSAGE="" if [ $LAST_CODE -ne 0 ]; then STATUS_COLOR=$RED_COLOR fi - export PS1="\[\e[${STATUS_COLOR}m\]{\[\e[m\]${MIDDLE_CHARACTER}\[\e[${STATUS_COLOR}m\]}\[\e[m\] \[\e[33m\]${current_dir}\[\e[m\] " + if [ -f "$DOTFILES_PATH/.dotly_update_available" ]; then + UPDATE_MESSAGE="📬 | " + fi + + export PS1="$UPDATE_MESSAGE\[\e[${STATUS_COLOR}m\]{\[\e[m\]${MIDDLE_CHARACTER}\[\e[${STATUS_COLOR}m\]}\[\e[m\] \[\e[33m\]${current_dir}\[\e[m\] " } diff --git a/shell/init-scripts/dotly_autoupdater b/shell/init-scripts/dotly_autoupdater index 49e62c94f..db3c6733c 100755 --- a/shell/init-scripts/dotly_autoupdater +++ b/shell/init-scripts/dotly_autoupdater @@ -1,4 +1,3 @@ #!/usr/bin/env bash -# If auto update is disabled then it should not run -"$DOTLY_PATH/dotly" autoupdate \ No newline at end of file +"$DOTLY_PATH/bin/dot" self autoupdate \ No newline at end of file diff --git a/shell/zsh/init-dotly.sh b/shell/zsh/init-dotly.sh index 097b43230..6b03bf237 100755 --- a/shell/zsh/init-dotly.sh +++ b/shell/zsh/init-dotly.sh @@ -34,6 +34,6 @@ prompt ${DOTLY_THEME:-codely} # Auto Init scripts at the end init_scripts_path="$DOTFILES_PATH/shell/init-scripts.enabled" mkdir -p "$init_scripts_path" -find "$init_scripts_path" -mindepth 1 -maxdepth 1 -type f -name '*' -print0 | grep -v \. | while read init_script; do - #[[ -f "$init_script" ]] && . "$init_script" - done +find "$init_scripts_path" -mindepth 1 -maxdepth 1 -type f,l -name '*' | while read -r init_script; do + . "$init_script" + done \ No newline at end of file diff --git a/shell/zsh/themes/prompt_codely_setup b/shell/zsh/themes/prompt_codely_setup index ecd784da4..41b7d2a00 100644 --- a/shell/zsh/themes/prompt_codely_setup +++ b/shell/zsh/themes/prompt_codely_setup @@ -19,7 +19,13 @@ prompt_codely_precmd() { } prompt_codely_setup() { - local prompt_codely_status='%(?:%F{green}{%F{white}▸%F{green}}:%F{red}{%F{white}▸%F{red}})' + local UPDATE_MESSAGE prompt_codely_status + + if [ -f "$DOTFILES_PATH/.dotly_update_available" ]; then + UPDATE_MESSAGE="📬 | " + fi + + prompt_codely_status='%(?:%F{green}{%F{white}▸%F{green}}:%F{red}{%F{white}▸%F{red}})' autoload -Uz add-zsh-hook && add-zsh-hook precmd prompt_codely_precmd @@ -31,7 +37,7 @@ prompt_codely_setup() { zstyle ':zim:git-info:dirty' format '%F{yellow}$DIRTY' zstyle ':zim:git-info:keys' format 'prompt' ' %F{cyan}%b%c %C%D' - PS1="${prompt_codely_status} \$(prompt_codely_pwd)\$(prompt_codely_git)%f " + PS1="${UPDATE_MESSAGE:-}${prompt_codely_status} \$(prompt_codely_pwd)\$(prompt_codely_git)%f " RPS1='' } From a777f45256cdb1b51cae5dc73a101ca5c5d5036c Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 2 Apr 2021 23:00:26 +0200 Subject: [PATCH 32/54] Deleted some debug information --- scripts/self/autoupdate | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/self/autoupdate b/scripts/self/autoupdate index 447d61114..062fa13c4 100755 --- a/scripts/self/autoupdate +++ b/scripts/self/autoupdate @@ -11,10 +11,5 @@ source "$DOTLY_PATH/scripts/self/utils/autoupdate.sh" ##? autoupdate docs::parse "$@" -DOTLY_AUTO_UPDATE_DAYS=0 -DOTLY_AUTO_UPDATE_MODE="info" # auto, info, prompt - -output::write "Async autoupdater checking for new version..." - set +eu # Needed to use async async "autoupdate::updater /Users/gtrabanco/MyCodes/dotly2" autoupdate::success autoupdate::reject \ No newline at end of file From dd07b376e8728b874e23527bbd136fa5a9e2ced2 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 2 Apr 2021 23:11:07 +0200 Subject: [PATCH 33/54] Deleted some debug information again due the git reset --hard I have to redoit. --- scripts/self/autoupdate | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/self/autoupdate b/scripts/self/autoupdate index 062fa13c4..5ccb25318 100755 --- a/scripts/self/autoupdate +++ b/scripts/self/autoupdate @@ -12,4 +12,4 @@ source "$DOTLY_PATH/scripts/self/utils/autoupdate.sh" docs::parse "$@" set +eu # Needed to use async -async "autoupdate::updater /Users/gtrabanco/MyCodes/dotly2" autoupdate::success autoupdate::reject \ No newline at end of file +async autoupdate::updater autoupdate::success autoupdate::reject \ No newline at end of file From effbfe89c47f722bb985d86cba90731d38fbb210 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Date: Sat, 3 Apr 2021 00:45:50 +0200 Subject: [PATCH 34/54] Fixed error with output::yesno which made this function to always returned true --- scripts/core/output.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/core/output.sh b/scripts/core/output.sh index f28291446..ba6d80fc3 100644 --- a/scripts/core/output.sh +++ b/scripts/core/output.sh @@ -45,8 +45,8 @@ output::yesno() { default_check="Nn" fi - output::question_default "$question" "$values" "PROMPT_REPLY" - [[ "$PROMPT_REPLY" =~ ^[$default_check] ]] + output::question "$question? [$values]" "PROMPT_REPLY" + [[ "${PROMPT_REPLY:-$default}" =~ ^[$default_check] ]] } output::empty_line() { echo ''; } -output::header() { output::empty_line; output::write "${bold_blue}---- $1 ----${normal}"; } \ No newline at end of file +output::header() { output::empty_line; output::write "${bold_blue}---- $1 ----${normal}"; } From 4d8d2e2a5b68b496be4a1b7d4f7488e6fcbeb3a4 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Sun, 4 Apr 2021 16:13:55 +0200 Subject: [PATCH 35/54] Fix error when try to execute a broken link to init script --- shell/bash/init-dotly.sh | 2 +- shell/zsh/init-dotly.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/bash/init-dotly.sh b/shell/bash/init-dotly.sh index 2ba704941..a949f125c 100755 --- a/shell/bash/init-dotly.sh +++ b/shell/bash/init-dotly.sh @@ -44,5 +44,5 @@ fi init_scripts_path="$DOTFILES_PATH/shell/init-scripts.enabled" mkdir -p "$init_scripts_path" find "$init_scripts_path" -mindepth 1 -maxdepth 1 -type l,f -name '*' | while read init_script; do - echo "$init_script" + [[ -e "$init_script" ]] && . "$init_script" done diff --git a/shell/zsh/init-dotly.sh b/shell/zsh/init-dotly.sh index 72de58bc3..d0f8718a4 100755 --- a/shell/zsh/init-dotly.sh +++ b/shell/zsh/init-dotly.sh @@ -35,5 +35,5 @@ prompt ${DOTLY_THEME:-codely} init_scripts_path="$DOTFILES_PATH/shell/init-scripts.enabled" mkdir -p "$init_scripts_path" find "$init_scripts_path" -mindepth 1 -maxdepth 1 -type f,l -name '*' | while read -r init_script; do - . "$init_script" + [[ -e "$init_script" ]] && . "$init_script" done From ae4a4df3f335fef379a8ef46aabe5c939f7cf9d0 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Sun, 4 Apr 2021 16:16:31 +0200 Subject: [PATCH 36/54] Fixed the use of files::check_if_path_is_older, refactored files::check_if_path_is_older to be more clear and clean in the usage --- scripts/core/files.sh | 6 +++++- scripts/self/utils/autoupdate.sh | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/core/files.sh b/scripts/core/files.sh index 54136cf93..9011ec635 100644 --- a/scripts/core/files.sh +++ b/scripts/core/files.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash files::check_if_path_is_older() { - [[ $(date -r "$1" +%s) -lt $(date -d "now - $2 days" +%s) ]] + local path number_of period + path="$1"; shift + number_of="${2:-0}" + period="${3:-days}" + [[ -e "$path" ]] && [[ $(date -r "$1" +%s) -lt $(date -d "now - $number_of $period" +%s) ]] } \ No newline at end of file diff --git a/scripts/self/utils/autoupdate.sh b/scripts/self/utils/autoupdate.sh index ed492b3c6..5a5f4edf2 100644 --- a/scripts/self/utils/autoupdate.sh +++ b/scripts/self/utils/autoupdate.sh @@ -17,7 +17,7 @@ autoupdate::updater() { [[ -f "$DOTFILES_PATH/.dotly_update_available" ]] && return 0 - if [[ $(date -r "$GIT_UPDATE_CHECK" +%s) -lt $(date -d "now - ${DOTLY_AUTO_UPDATE_DAYS:-7} days" +%s) ]] &&\ + if files::check_if_path_is_older "$GIT_UPDATE_CHECK" "${DOTLY_AUTO_UPDATE_DAYS:-7}" "days" &&\ [ "$(git rev-parse HEAD)" != "$(git ls-remote $(git rev-parse --abbrev-ref @{u} | sed 's/\// /g') | cut -f1)" ] then touch "$DOTFILES_PATH/.dotly_update_available" From b053231e4c96271446808a51357958cf18cb17e2 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Sun, 4 Apr 2021 16:22:28 +0200 Subject: [PATCH 37/54] Fixed the use of shift when not necessary --- scripts/core/files.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/core/files.sh b/scripts/core/files.sh index 9011ec635..248d0e5f2 100644 --- a/scripts/core/files.sh +++ b/scripts/core/files.sh @@ -2,7 +2,7 @@ files::check_if_path_is_older() { local path number_of period - path="$1"; shift + path="$1" number_of="${2:-0}" period="${3:-days}" [[ -e "$path" ]] && [[ $(date -r "$1" +%s) -lt $(date -d "now - $number_of $period" +%s) ]] From 13b6516805255292227775d7bfdcac60ec8d2754 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Sun, 4 Apr 2021 16:28:10 +0200 Subject: [PATCH 38/54] Fixed the usage of variable name path inside 'files::check_if_path_is_older' that makes the function to crash --- scripts/core/files.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/core/files.sh b/scripts/core/files.sh index 248d0e5f2..7b73e3b32 100644 --- a/scripts/core/files.sh +++ b/scripts/core/files.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash files::check_if_path_is_older() { - local path number_of period - path="$1" + local path_to_check number_of period + path_to_check="$1" number_of="${2:-0}" period="${3:-days}" - [[ -e "$path" ]] && [[ $(date -r "$1" +%s) -lt $(date -d "now - $number_of $period" +%s) ]] + [[ -e "$path_to_check" ]] && [[ $(date -r "$path_to_check" +%s) -lt $(date -d "now - $number_of $period" +%s) ]] } \ No newline at end of file From 538f7d3a298942a87263b913c8646b90dc5090c8 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Mon, 5 Apr 2021 20:44:06 +0200 Subject: [PATCH 39/54] Replaced 'source' for '.' as posix standard... Delete some debug comments in 'autoupdate.sh' lib. Fixed status messages of 'dot self init status' that were incorrectly show --- scripts/self/init | 6 +++--- scripts/self/utils/autoupdate.sh | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/self/init b/scripts/self/init index 908864075..d8ba7de53 100755 --- a/scripts/self/init +++ b/scripts/self/init @@ -1,7 +1,7 @@ #!/usr/bin/env bash -source "$DOTLY_PATH/scripts/core/_main.sh" -source "$DOTLY_PATH/scripts/self/utils/init.sh" +. "$DOTLY_PATH/scripts/core/_main.sh" +. "$DOTLY_PATH/scripts/self/utils/init.sh" ##? Enable/Disable init scripts ##? @@ -130,7 +130,7 @@ case "${1:-}" in fi else # If there is no script_name, gives the status of all - for item in "${init_scripts[@]}"; do + for item in ${init_scripts[@]}; do init::status "$item" &&\ output::solution "'$item'... Enabled." ||\ output::error "'$item'... Disabled." diff --git a/scripts/self/utils/autoupdate.sh b/scripts/self/utils/autoupdate.sh index 5a5f4edf2..613fb86c1 100644 --- a/scripts/self/utils/autoupdate.sh +++ b/scripts/self/utils/autoupdate.sh @@ -1,8 +1,7 @@ #!/usr/bin/env bash # DOTLY_AUTO_UPDATE_DAYS=${DOTLY_AUTO_UPDATE_DAYS:-7} -# DOTLY_AUTO_UPDATE_MODE=${DOTLY_AUTO_UPDATE_MODE:-reminder} # prompt -# async "autoupdate::updater '/Users/gtrabanco/MyCodes/dotly2'" autoupdate::success autoupdate::reject +# DOTLY_AUTO_UPDATE_MODE=${DOTLY_AUTO_UPDATE_MODE:-reminder} # prompt, auto autoupdate::updater() { From 8be2559b56e0a52eef4c0a424a097ba85e85ebd2 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Mon, 5 Apr 2021 20:58:32 +0200 Subject: [PATCH 40/54] Trying to fix error that produce not to enable/disable multiple scripts simoultaneously --- scripts/self/init | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/self/init b/scripts/self/init index d8ba7de53..08ef0a0ef 100755 --- a/scripts/self/init +++ b/scripts/self/init @@ -71,8 +71,9 @@ case "${1:-}" in fi [[ -z "$to_enable" ]] && exit 0 - for item in "${to_enable[@]}"; do + for item in ${to_enable[@]}; do init::enable "$item" + if init::status "$item"; then output::solution "Init script '$item'... Enabled" else @@ -109,14 +110,13 @@ case "${1:-}" in fi [[ -z "$to_disable" ]] && exit 0 - init::disable "${to_disable[@]}" - for item in "${to_disable[@]}"; do - output::answer "Init script '$item'..." + for item in ${to_disable[@]}; do + init::disable "$item" if ! init::status "$item"; then - output::solution "Disabled" + output::solution "Init script '$item'... Disabled" else - output::error "Could not be disabled." + output::error "Init script '$item'... Could not be disabled." fi done ;; From a9feb37dd62c4c069dbc39d23895f9748ef5f64e Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Wed, 7 Apr 2021 12:45:12 +0200 Subject: [PATCH 41/54] Fixed that scripts ended in DOTLY_PATH instead of current dir due to change dir in the update script --- scripts/self/update | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/self/update b/scripts/self/update index dbff3eb78..68f0f48ca 100755 --- a/scripts/self/update +++ b/scripts/self/update @@ -10,6 +10,8 @@ source "$DOTLY_PATH/scripts/core/_main.sh" ##? update docs::parse "$@" +current_dir="$(pwd)" + cd "$DOTFILES_PATH" branch=$(git config -f .gitmodules submodule.modules/dotly.branch) @@ -21,4 +23,6 @@ git submodule update --init --recursive > /dev/null 2>&1 output::answer '✅ dotly updated to the latest version' -rm -f "$DOTFILES_PATH/.dotly_update_available" \ No newline at end of file +rm -f "$DOTFILES_PATH/.dotly_update_available" + +cd "$current_dir" \ No newline at end of file From 87c3b86db970e18476781b892219f6269f29808e Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 9 Apr 2021 00:06:47 +0200 Subject: [PATCH 42/54] Fixed output '1' always executes async. Deleted not necessary functions --- scripts/core/async.sh | 373 ++++++++++-------------------------------- 1 file changed, 87 insertions(+), 286 deletions(-) diff --git a/scripts/core/async.sh b/scripts/core/async.sh index eb5f6f620..0f088db3a 100644 --- a/scripts/core/async.sh +++ b/scripts/core/async.sh @@ -1,323 +1,124 @@ #!/usr/bin/env bash # This was literally copied from: https://github.com/zombieleet/async-bash - -# This script implements 3 asynchronous function -# setTimeout -# setInterval -# async -# killJob function is not asynchronous - # check the README.md for information on how to use this script -declare -a JOB_IDS +# set +eu +declare -a JOB_IDS declare -i JOBS=1; -#source ./functions.sh; - -setTimeout() { - - local command="$1" - local after="$2" - - read -d " " comm <<<"${command}" - - #declare -F $comm &>/dev/null - - local _isDef=$(type -t ${comm}) - - if [[ -z "${_isDef}" ]];then - printf "%s\n" "\"${command}\" is not of type { function, command} " - - return 1; - fi - - - [[ ! $after =~ ^[[:digit:]]+$ ]] && { - printf "%s\n" "require an integer as the second argument but got \"$after\" " - - return 1; - } - - { - sleep ${after} - $command - } & - - JOB_IDS+=( "${JOBS} ${command}" ) - - - - read -d " " -a __kunk__ <<< "${JOB_IDS[$(( ${#JOB_IDS[@]} - 1))]}" - - echo ${__kunk__} - - : $(( JOBS++ )) - -} - -setInterval() { - - local command="$1" - local after="$2" - - read -d " " comm <<<"${command}" - - - - local _isDef=$(type -t ${comm}) - - if [[ -z "${_isDef}" ]];then - printf "%s\n" "\"${command}\" is not of type { function, command} " - - return 1; - fi - - - [[ ! $after =~ ^[[:digit:]]+$ ]] && { - printf "%s\n" "require an integer as the second argument but got \"$after\" " - - return 1; - } - - { - while sleep ${after};do - $command - done - } & - - JOB_IDS+=( "${JOBS} ${command}" ) - - read -d " " -a __kunk__ <<< "${JOB_IDS[$(( ${#JOB_IDS[@]} - 1))]}" - - echo ${__kunk__} - - : $(( JOBS++ )) -} - killJob() { + local jobToKill signal __al__signals isSig + + jobToKill="$1" + signal="$2" + signal=${signal^^} - local jobToKill="$1" - local signal="$2" + [[ ! $jobToKill =~ ^[[:digit:]]+$ ]] && { + printf "%s\n" "\"$jobToKill\" should be an integer "; + return 1; + } - signal=${signal^^} - [[ ! $jobToKill =~ ^[[:digit:]]+$ ]] && { - - printf "%s\n" "\"$jobToKill\" should be an integer "; - - return 1; + { + [[ -z "$signal" ]] && { + signal="SIGTERM" } + } || { + # for loop worked better than read line in this case + __al__signals=$(kill -l); + isSig=0; + for sig in ${__al__signals}; do + [[ ! $sig =~ ^[[:digit:]]+\)$ ]] && { + [[ $signal == $sig ]] && { + isSig=1; + break; + } + } + done - - { - [[ -z "$signal" ]] && { - signal="SIGTERM" - } - } || { - # for loop worked better than read line in this case - local __al__signals=$(kill -l); - local isSig=0; - for sig in ${__al__signals};do - - [[ ! $sig =~ ^[[:digit:]]+\)$ ]] && { - [[ $signal == $sig ]] && { - isSig=1; - break; - } - } - done - - (( isSig != 1 )) && { - signal="SIGTERM" - } - + (( isSig != 1 )) && { + signal="SIGTERM" } - - - - for job in ${JOB_IDS[@]};do - - # increment job to 1 since array index starts from 0 - read -d " " -a __kunk__ <<< "${JOB_IDS[$job]}" - - (( __kunk__ == jobToKill )) && { - - - read -d " " -a __kunk__ <<< "${JOB_IDS[$job]}" - - kill -${signal} %${__kunk__} - - local status=$? - - (( status != 0 )) && { - - - printf "cannot kill %s %d\n" "${JOB_IDS[$job]}" "${__kunk__}" - - return 1; - } - - printf "%d killed with %s\n" "${__kunk__}" "${signal}" - - return 0; - } - - done + } + + + + for job in ${JOB_IDS[@]};do + # increment job to 1 since array index starts from 0 + read -r -d " " -a __kunk__ <<< "${JOB_IDS[$job]}" + (( __kunk__ == jobToKill )) && { + read -r -d " " -a __kunk__ <<< "${JOB_IDS[$job]}" + + kill -${signal} %${__kunk__} + + status=$? + + (( status != 0 )) && { + printf "cannot kill %s %d\n" "${JOB_IDS[$job]}" "${__kunk__}" + return 1; + } + + printf "%d killed with %s\n" "${__kunk__}" "${signal}" + + return 0; + } + done } async() { - - local commandToExec="$1" - local resolve="$2" - local reject="$3" + local cmdToExec resolve reject _c __temp status - [[ -z "$commandToExec" ]] || [[ -z "$reject" ]] || [[ -z "$resolve" ]] && { - printf "%s\n" "Insufficient number of arguments"; - return 1; - } + cmdToExec="$1" + resolve="$2" + reject="$3" + + [[ -z "$cmdToExec" ]] || [[ -z "$reject" ]] || [[ -z "$resolve" ]] && { + printf "%s\n" "Insufficient number of arguments"; + return 1; + } - local __temp=( "$commandToExec" "$reject" "$resolve" ) + __temp=( "$cmdToExec" "$reject" "$resolve" ) - for _c in "${__temp[@]}";do - + for _c in "${__temp[@]}"; do + read -r -d " " comm <<<"${_c}" + type "${comm}" &>/dev/null - read -d " " comm <<<"${_c}" + status=$? - type "${comm}" &>/dev/null - - local status=$? - - (( status != 0 )) && { - printf "\"%s\" is neither a function nor a recognized command\n" "${_c}"; + (( status != 0 )) && { + printf "\"%s\" is neither a function nor a recognized cmd\n" "${_c}"; unset _c return 1; - } - - done - - unset __temp ; unset _c - - { - - __result=$($commandToExec) - - status=$? - - (( status == 0 )) && { - $resolve "${__result}" - - } || { - $reject "${status}" - } - unset __result - } & - - - - JOB_IDS+=( "${JOBS} ${command}" ) - - read -d " " -a __kunk__ <<< "${JOB_IDS[$(( ${#JOB_IDS[@]} - 1))]}" - - echo ${__kunk__} - - - : $(( JOBS++ )) - -} - - -parallel() { - - #local funcArray="${@:1:$(( ${#@} - 1 ))}" - - local mainFunc="${1}" - local funcArray="${2}" - local finalFunc="${3}" - - local totalArgs=${#@} - - (( totalArgs < 3 )) && { - printf "%s\n" "Insufficient number of argument" - return 1; } - - read -d " " __cmd <<<"${mainFunc}" - - local _isDef=$(type -t ${__cmd}) + done + unset __temp _c - [[ -z $_isDef ]] && { - printf "%s\n" "${__cmd} is not of type { function , alias , builtin or file }" - return 1; - } - - [[ "$(type -t $finalFunc)" != "function" ]] && { - printf "%s\n" "${finalFunc} is not of type { function }" - return 1; - } + { + __result=$($cmdToExec) + status=$? - for __arr in ${funcArray};do - - local __isfunc=$(type -t ${__arr}) - - [[ $__isfunc != "function" ]] && { - - printf "%s\n" "${__arr} is not of type { function }" - return 1; - - } - - declare __fArray+=( ${__arr} ) - done - - unset __arr - - { - __result=$($mainFunc) - - status=$? - - (( status != 0 )) && { - $finalFunc "" "${__result}" - return $?; - } - - local _t=0 - - for __async in "${__fArray[@]}";do - - __result=$(${__async} "${__result}") - - status=$? - - (( status != 0 )) && { - $finalFunc "" "${__result}" - - # _t has no use here, since we will be returning from this function - # it was only use for clarity - - _t=1 - return $? - } - - done - - (( _t == 0 )) && { - $finalFunc "${__result}" "" - } - } & - - JOB_IDS+=( "${JOBS} ${command}" ) + if (( status == 0 )) + then + $resolve "${__result}" + else + $reject "${status}" + fi + unset __result + } & + + JOB_IDS+=( "${JOBS} ${cmd}" ) - read -d " " -a __kunk__ <<< "${JOB_IDS[$(( ${#JOB_IDS[@]} - 1))]}" + read -r -d " " -a __kunk__ <<< "${JOB_IDS[$(( ${#JOB_IDS[@]} - 1))]}" - echo ${__kunk__} + #echo ${__kunk__} + + : $(( JOBS++ )) - : $(( JOBS++ )) } \ No newline at end of file From 13262d27222410c52848357e7c31315834fc93c1 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 9 Apr 2021 00:08:16 +0200 Subject: [PATCH 43/54] Fixed double negation error --- scripts/core/output.sh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/scripts/core/output.sh b/scripts/core/output.sh index ba6d80fc3..00f54a73e 100644 --- a/scripts/core/output.sh +++ b/scripts/core/output.sh @@ -25,28 +25,27 @@ output::question() { fi } output::question_default() { - local question="$1" - local default_value="$2" - local var_name="$3" + local question default_value var_name + question="$1" + default_value="$2" + var_name="$3" output::question "$question? [$default_value]" "$var_name" eval "$var_name=\"\${$var_name:-$default_value}\"" } output::yesno() { - local question="$1" - local default="${2:-Y}" - local PROMPT_REPLY values default_check + local question default PROMPT_REPLY values + question="$1" + default="${2:-Y}" if [[ "$default" =~ ^[Yy] ]]; then values="Y/n" - default_check="Yy" else values="y/N" - default_check="Nn" fi output::question "$question? [$values]" "PROMPT_REPLY" - [[ "${PROMPT_REPLY:-$default}" =~ ^[$default_check] ]] + [[ "${PROMPT_REPLY:-$default}" =~ ^[Yy] ]] } output::empty_line() { echo ''; } output::header() { output::empty_line; output::write "${bold_blue}---- $1 ----${normal}"; } From f7a9c7acc21a6629432841825b033f778786d0fe Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 9 Apr 2021 00:08:58 +0200 Subject: [PATCH 44/54] Not right idented .sh files in vscode --- .editorconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.editorconfig b/.editorconfig index 361cd4145..84b75025a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,6 +2,10 @@ indent_style = space indent_size = 2 +[*.sh] +indent_style = space +indent_size = 2 + [.zshrc] indent_style = space indent_size = 2 From f5d9dcde5ad1a1c3344997409b8c6aaa6b183326 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 9 Apr 2021 00:10:29 +0200 Subject: [PATCH 45/54] Restored docpars as should be --- scripts/dotfiles/create | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dotfiles/create b/scripts/dotfiles/create index c036853a2..c33c30d07 100755 --- a/scripts/dotfiles/create +++ b/scripts/dotfiles/create @@ -8,7 +8,7 @@ source "$DOTLY_PATH/scripts/core/templating.sh" ##? Create the dotfiles structure ##? ##? Usage: -##? test +##? create [dotfiles_path] ##? docs::parse "$@" From 8a06ae8bea9edae1cc3cc9e7f9732704324f3e6e Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 9 Apr 2021 00:18:58 +0200 Subject: [PATCH 46/54] Remove comments and not necessary comments --- scripts/self/utils/init.sh | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/scripts/self/utils/init.sh b/scripts/self/utils/init.sh index 50f51fc9e..7913651c7 100644 --- a/scripts/self/utils/init.sh +++ b/scripts/self/utils/init.sh @@ -1,21 +1,17 @@ #!/usr/bin/env bash -# Needed variables DOTLY_INIT_SCRIPTS_PATH=${DOTLY_INIT_SCRIPTS_PATH:-$DOTLY_PATH/shell/init-scripts} DOTFILES_INIT_SCRIPTS_PATH=${DOTFILES_INIT_SCRIPTS_PATH:-$DOTFILES_PATH/shell/init-scripts} ENABLED_INIT_SCRIPTS_PATH=${ENABLED_INIT_SCRIPTS_PATH:-$DOTFILES_PATH/shell/init-scripts.enabled} -# Check if init script exists in dotly or dotfiles init::exists_script() { [[ -f "$DOTLY_INIT_SCRIPTS_PATH/$1" ]] || [[ -f "$DOTFILES_INIT_SCRIPTS_PATH" ]] } -# check if init script is enabled or disabled init::status() { init::exists_script "$1" && [[ -f "$ENABLED_INIT_SCRIPTS_PATH/$1" ]] } -# Stored init scripts init::get_scripts() { [[ -d "$DOTLY_INIT_SCRIPTS_PATH" ]] &&\ [[ -d "$DOTFILES_INIT_SCRIPTS_PATH" ]] &&\ @@ -24,7 +20,6 @@ init::get_scripts() { xargs -I _ basename _ | sort | uniq } -# Enabled init scripts init::get_enabled() { [[ -d "$ENABLED_INIT_SCRIPTS_PATH" ]] &&\ find "$ENABLED_INIT_SCRIPTS_PATH" -name "*" -type l |\ @@ -39,7 +34,6 @@ init::fzf() { --preview "echo 'Press Tab+Shift to select multiple options.\nPress Ctrl+C to exit with no selection.'" } -# Enable init scripts init::enable() { local from1="$DOTLY_INIT_SCRIPTS_PATH" local from2="$DOTFILES_INIT_SCRIPTS_PATH" @@ -62,21 +56,12 @@ init::enable() { done } -# Disable init scripts init::disable() { local enabled_path="$ENABLED_INIT_SCRIPTS_PATH" local item for item in "$@"; do - # Check if exists in DOTLY_PATH [[ -f "$enabled_path/$item" ]] &&\ rm -f "$enabled_path/$item" - - # Check if exists in DOTFILES_PATH - # This will prevail over DOTLY_PATH - [[ -f "$from2/$item" ]] &&\ - [[ ! -f "$to/$item" ]] &&\ - rm -f "$to/$item" &&\ - ln -s "$from2/$item" "$to/" done } \ No newline at end of file From 08e191934dcd5c0391a9dfa5140515330db4c485 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 9 Apr 2021 00:35:16 +0200 Subject: [PATCH 47/54] Remove source and use '.' which is posix compilant --- scripts/self/autoupdate | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/self/autoupdate b/scripts/self/autoupdate index 5ccb25318..85bbef42b 100755 --- a/scripts/self/autoupdate +++ b/scripts/self/autoupdate @@ -2,8 +2,8 @@ set -euo pipefail -source "$DOTLY_PATH/scripts/core/_main.sh" -source "$DOTLY_PATH/scripts/self/utils/autoupdate.sh" +. "$DOTLY_PATH/scripts/core/_main.sh" +. "$DOTLY_PATH/scripts/self/utils/autoupdate.sh" ##? Async autoupdate dotly to avoid load all core functions in default bash ##? From 4ffe258a3209668c492b7408cb7338e6dcb12fe3 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 9 Apr 2021 01:36:07 +0200 Subject: [PATCH 48/54] Added github api command. Check minor version. Update silently is different than auto. Minor version update prepared to run when available through tags. --- dotfiles_template/.gitignore | 4 +++ scripts/core/github.sh | 41 +++++++++++++++++++++++++++++++ scripts/core/platform.sh | 31 +++++++++++++++++++++++ scripts/self/update | 1 + scripts/self/utils/autoupdate.sh | 42 ++++++++++++++++++++++++++------ 5 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 dotfiles_template/.gitignore create mode 100644 scripts/core/github.sh diff --git a/dotfiles_template/.gitignore b/dotfiles_template/.gitignore new file mode 100644 index 000000000..142a7c959 --- /dev/null +++ b/dotfiles_template/.gitignore @@ -0,0 +1,4 @@ +.dotly_update_available +.dotly_updated + +.cached_github_api_calls \ No newline at end of file diff --git a/scripts/core/github.sh b/scripts/core/github.sh new file mode 100644 index 000000000..fa6e28724 --- /dev/null +++ b/scripts/core/github.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# Api Url +readonly GITHUB_API_URL="https://api.github.com/repos" +readonly GITHUB_DOTLY_REPOSITORY="CodelyTV/dotly" +readonly GITHUB_CACHE_PETITIONS="$DOTFILES_PATH/.cached_github_api_calls" + +github::curl() { + local url CURL_BIN + url="${1:-$(/dev/null" +} + +github::cached_curl() { + local md5command cached_request_file_path _command url + url=${1:-$( "$cached_request_file_path" + eval "$_command" > "$cached_request_file_path" + fi + + cat "$cached_request_file_path" +} \ No newline at end of file diff --git a/scripts/core/platform.sh b/scripts/core/platform.sh index 6a5ba9e92..58b2499e3 100644 --- a/scripts/core/platform.sh +++ b/scripts/core/platform.sh @@ -62,6 +62,37 @@ platform::semver_compare() { fi } +platform::semver_is_minor_patch_update() { + normalize_ver() { + echo "${${1//./ }//v/}" + } + + compare_ver() { + [[ $1 -lt $2 ]] && echo -1 && return + [[ $1 -gt $2 ]] && echo 1 && return + + echo 0 + } + + v1="$(normalize_ver $1)" + v2="$(normalize_ver $2)" + + major1="$(echo $v1 | awk '{print $1}')" + major2="$(echo $v2 | awk '{print $1}')" + + minor1="$(echo $v1 | awk '{print $2}')" + minor2="$(echo $v2 | awk '{print $2}')" + + patch1="$(echo $v1 | awk '{print $3}')" + patch2="$(echo $v2 | awk '{print $3}')" + + compare_major="$(compare_ver $major1 $major2)" + compare_minor="$(compare_ver $minor1 $minor2)" + compare_patch="$(compare_ver $patch1 $patch2)" + + [[ $compare_major -eq 0 ]] && { [[ $compare_minor -ne 0 ]] || [[ $compare_patch -ne 0 ]]; } +} + platform::get_script_path() { echo "$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" } diff --git a/scripts/self/update b/scripts/self/update index 68f0f48ca..9ed0c97a6 100755 --- a/scripts/self/update +++ b/scripts/self/update @@ -24,5 +24,6 @@ git submodule update --init --recursive > /dev/null 2>&1 output::answer '✅ dotly updated to the latest version' rm -f "$DOTFILES_PATH/.dotly_update_available" +[ "$DOTLY_AUTO_UPDATE_MODE" != "silent" ] && touch "$DOTFILES_PATH/.dotly_updated" cd "$current_dir" \ No newline at end of file diff --git a/scripts/self/utils/autoupdate.sh b/scripts/self/utils/autoupdate.sh index 613fb86c1..155adf640 100644 --- a/scripts/self/utils/autoupdate.sh +++ b/scripts/self/utils/autoupdate.sh @@ -1,8 +1,6 @@ #!/usr/bin/env bash -# DOTLY_AUTO_UPDATE_DAYS=${DOTLY_AUTO_UPDATE_DAYS:-7} -# DOTLY_AUTO_UPDATE_MODE=${DOTLY_AUTO_UPDATE_MODE:-reminder} # prompt, auto - +. "$DOTLY_PATH/scripts/core/github.sh" autoupdate::updater() { local CURRENT_DIR GIT_UPDATE_CHECK @@ -14,9 +12,17 @@ autoupdate::updater() { # Change to dotly path cd "$GIT_UPDATE_CHECK" || return 1 + [[ -f "$DOTFILES_PATH/.dotly_updated" ]] && { + output::empty_line + output::write " 🥳 🎉 🍾 DOTLY UPDATED 🥳 🎉 🍾 " + output::empty_line + rm "$DOTFILES_PATH/.dotly_updated" + } + [[ -f "$DOTFILES_PATH/.dotly_update_available" ]] && return 0 - if files::check_if_path_is_older "$GIT_UPDATE_CHECK" "${DOTLY_AUTO_UPDATE_DAYS:-7}" "days" &&\ + if files::check_if_path_is_older "$GIT_UPDATE_CHECK" "${DOTLY_AUTO_UPDATE_PERIOD_IN_DAYS:-7}" "days" &&\ + # shellcheck disable=SC2048 [ "$(git rev-parse HEAD)" != "$(git ls-remote $(git rev-parse --abbrev-ref @{u} | sed 's/\// /g') | cut -f1)" ] then touch "$DOTFILES_PATH/.dotly_update_available" @@ -26,8 +32,13 @@ autoupdate::updater() { } autoupdate::success() { + local latest_github_version current_dotly_version if [[ -f "$DOTFILES_PATH/.dotly_update_available" ]]; then - case "${DOTLY_AUTO_UPDATE_MODE:-reminder}" in + case "$(str::to_lower "${DOTLY_AUTO_UPDATE_MODE:-minor}")" in + "silent") + "$DOTLY_PATH/bin/dot" self update + rm -f "$DOTFILES_PATH/.dotly_update_available" + ;; "auto"|"autoupdate"|"auto-update"|"update") output::answer "🚀 Updating DOTLY Automatically" "$DOTLY_PATH/bin/dot" self update @@ -41,8 +52,25 @@ autoupdate::success() { output::write " ---------------------------------------------" output::empty_line ;; - *) # prompt or reminder... - # Nothing to do here + "minor"|"only_minor") + # Needs a file in DOTLY_PATH called VERSION with current installed VERSION + latest_github_version=$(github::cached_curl "$GITHUB_API_URL/$GITHUB_DOTLY_REPOSITORY/tags" | jq -r '.[0].name' | uniq) + current_dotly_version="0.0.0" + [ -f "$DOTLY_PATH/VERSION" ] && current_dotly_version="$(cat "$DOTLY_PATH/VERSION")" + + if [[ -n "$latest_github_version" ]] &&\ + [[ -n "$current_dotly_version" ]] &&\ + platform::semver_is_minor_patch_update "$current_dotly_version" "$latest_github_version" + then + output::answer "🚀 Updating DOTLY Automatically" + "$DOTLY_PATH/bin/dot" self update + output::solution "Updated, restart your terminal." + fi + + rm -f "$DOTFILES_PATH/.dotly_update_available" + ;; + *) # Prompt + #Nothing to do when only show a inbox in prompt ;; esac fi From 561ff1e3bb96186b2e1bd910cfd0c9f0f34bf210 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 9 Apr 2021 01:41:07 +0200 Subject: [PATCH 49/54] Fixed realtime prompt update --- shell/bash/themes/codely.sh | 12 ++++++++---- shell/zsh/themes/prompt_codely_setup | 12 +++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/shell/bash/themes/codely.sh b/shell/bash/themes/codely.sh index d1bb19904..7121eb0fa 100644 --- a/shell/bash/themes/codely.sh +++ b/shell/bash/themes/codely.sh @@ -4,6 +4,12 @@ MIDDLE_CHARACTER="◂" GREEN_COLOR="32" RED_COLOR="31" +prompt_dotly_update() { + if [ -f "$DOTFILES_PATH/.dotly_update_available" ]; then + UPDATE_MESSAGE="📥 | " + fi +} + codely_theme() { LAST_CODE="$?" current_dir=$(dot core short_pwd) @@ -14,9 +20,7 @@ codely_theme() { STATUS_COLOR=$RED_COLOR fi - if [ -f "$DOTFILES_PATH/.dotly_update_available" ]; then - UPDATE_MESSAGE="📬 | " - fi - export PS1="$UPDATE_MESSAGE\[\e[${STATUS_COLOR}m\]{\[\e[m\]${MIDDLE_CHARACTER}\[\e[${STATUS_COLOR}m\]}\[\e[m\] \[\e[33m\]${current_dir}\[\e[m\] " + + export PS1="\$(prompt_dotly_update)\[\e[${STATUS_COLOR}m\]{\[\e[m\]${MIDDLE_CHARACTER}\[\e[${STATUS_COLOR}m\]}\[\e[m\] \[\e[33m\]${current_dir}\[\e[m\] " } diff --git a/shell/zsh/themes/prompt_codely_setup b/shell/zsh/themes/prompt_codely_setup index 41b7d2a00..a271f5e0e 100644 --- a/shell/zsh/themes/prompt_codely_setup +++ b/shell/zsh/themes/prompt_codely_setup @@ -18,12 +18,14 @@ prompt_codely_precmd() { (( ${+functions[git-info]} )) && git-info } -prompt_codely_setup() { - local UPDATE_MESSAGE prompt_codely_status - +prompt_dotly_autoupdate() { if [ -f "$DOTFILES_PATH/.dotly_update_available" ]; then - UPDATE_MESSAGE="📬 | " + print -n "📥 | " fi +} + +prompt_codely_setup() { + local UPDATE_MESSAGE prompt_codely_status prompt_codely_status='%(?:%F{green}{%F{white}▸%F{green}}:%F{red}{%F{white}▸%F{red}})' @@ -37,7 +39,7 @@ prompt_codely_setup() { zstyle ':zim:git-info:dirty' format '%F{yellow}$DIRTY' zstyle ':zim:git-info:keys' format 'prompt' ' %F{cyan}%b%c %C%D' - PS1="${UPDATE_MESSAGE:-}${prompt_codely_status} \$(prompt_codely_pwd)\$(prompt_codely_git)%f " + PS1="\$(prompt_dotly_autoupdate)${prompt_codely_status} \$(prompt_codely_pwd)\$(prompt_codely_git)%f " RPS1='' } From 27335de813b38cfce6ead19a5a9b5ac1b3443fce Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 9 Apr 2021 01:52:52 +0200 Subject: [PATCH 50/54] Not lifetime cache for github petitions --- scripts/core/github.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/core/github.sh b/scripts/core/github.sh index fa6e28724..e023048ec 100644 --- a/scripts/core/github.sh +++ b/scripts/core/github.sh @@ -4,6 +4,7 @@ readonly GITHUB_API_URL="https://api.github.com/repos" readonly GITHUB_DOTLY_REPOSITORY="CodelyTV/dotly" readonly GITHUB_CACHE_PETITIONS="$DOTFILES_PATH/.cached_github_api_calls" +GITHUB_CACHE_PETITIONS_PERIOD_IN_DAYS="${GITHUB_CACHE_PETITIONS_PERIOD_IN_DAYS:-1}" github::curl() { local url CURL_BIN @@ -31,9 +32,11 @@ github::cached_curl() { md5command="$(md5 -s "$_command")" cached_request_file_path="$GITHUB_CACHE_PETITIONS/$md5command" + [[ -f "$cached_request_file_path" ]] &&\ + files::check_if_path_is_older "$cached_request_file_path" "$GITHUB_CACHE_PETITIONS_PERIOD_IN_DAYS" + # Cache result if is not if [ ! -f "$cached_request_file_path" ]; then - #debug::log_exec $command > "$cached_request_file_path" eval "$_command" > "$cached_request_file_path" fi From c61713e79ed5042aed532a060fd4c686d08acb07 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 9 Apr 2021 01:56:11 +0200 Subject: [PATCH 51/54] Added a new line at the end of the file --- dotfiles_template/shell/paths.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotfiles_template/shell/paths.sh b/dotfiles_template/shell/paths.sh index 11b30b606..af62f351f 100644 --- a/dotfiles_template/shell/paths.sh +++ b/dotfiles_template/shell/paths.sh @@ -15,4 +15,4 @@ export path=( "/usr/bin" "/usr/sbin" "/sbin" -) \ No newline at end of file +) From 367b26593418898efd1e3b6fea57e1b549ae760a Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 9 Apr 2021 02:02:31 +0200 Subject: [PATCH 52/54] Solved variable names --- dotfiles_template/shell/exports.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotfiles_template/shell/exports.sh b/dotfiles_template/shell/exports.sh index 9599f55fa..e75ae3c13 100644 --- a/dotfiles_template/shell/exports.sh +++ b/dotfiles_template/shell/exports.sh @@ -1,5 +1,5 @@ -export DOTLY_AUTO_UPDATE_DAYS=7 -export DOTLY_AUTO_UPDATE_MODE="reminder" # reminder*, auto, prompt +export DOTLY_AUTO_UPDATE_PERIOD_IN_DAYS=7 +export DOTLY_AUTO_UPDATE_MODE="minor" # silent, auto, minor*, info, prompt export JAVA_HOME='/Library/Java/JavaVirtualMachines/amazon-corretto-15.jdk/Contents/Home' export GEM_HOME="$HOME/.gem" From ad439a591b8ca4a8e0bb92d343abb78a53384f59 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 9 Apr 2021 02:21:58 +0200 Subject: [PATCH 53/54] Deleted unused function --- scripts/core/platform.sh | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/scripts/core/platform.sh b/scripts/core/platform.sh index 58b2499e3..67cc2657d 100644 --- a/scripts/core/platform.sh +++ b/scripts/core/platform.sh @@ -24,44 +24,6 @@ platform::wsl_home_path(){ wslpath "$(wslvar USERPROFILE 2> /dev/null)" } -# Used as reference: https://gist.github.com/maxrimue/ca69ee78081645e1ef62 -platform::semver_compare() { - normalize_ver() { - echo "${${1//./ }//v/}" - } - - compare_ver() { - [[ $1 -lt $2 ]] && echo -1 && return - [[ $1 -gt $2 ]] && echo 1 && return - - echo 0 - } - - v1="$(normalize_ver $1)" - v2="$(normalize_ver $2)" - - major1="$(echo $v1 | awk '{print $1}')" - major2="$(echo $v2 | awk '{print $1}')" - - minor1="$(echo $v1 | awk '{print $2}')" - minor2="$(echo $v2 | awk '{print $2}')" - - patch1="$(echo $v1 | awk '{print $3}')" - patch2="$(echo $v2 | awk '{print $3}')" - - compare_major="$(compare_ver $major1 $major2)" - compare_minor="$(compare_ver $minor1 $minor2)" - compare_patch="$(compare_ver $patch1 $patch2)" - - if [[ $compare_major -ne 0 ]]; then - echo "$compare_major" - elif [[ $compare_minor -ne 0 ]]; then - echo "$compare_minor" - else - echo "$compare_patch" - fi -} - platform::semver_is_minor_patch_update() { normalize_ver() { echo "${${1//./ }//v/}" From e098eedf4082b2fbd0b52ada08104b08bc5aec41 Mon Sep 17 00:00:00 2001 From: Gabriel Trabanco Llano Date: Fri, 9 Apr 2021 23:28:36 +0200 Subject: [PATCH 54/54] Added scripts to create scripts from the terminal --- scripts/dotly/create | 99 ++++++++++++++++++++++ scripts/dotly/helpers/script-template | 38 +++++++++ scripts/dotly/helpers/script-template-more | 49 +++++++++++ scripts/dotly/install-remote | 71 ++++++++++++++++ 4 files changed, 257 insertions(+) create mode 100755 scripts/dotly/create create mode 100644 scripts/dotly/helpers/script-template create mode 100644 scripts/dotly/helpers/script-template-more create mode 100755 scripts/dotly/install-remote diff --git a/scripts/dotly/create b/scripts/dotly/create new file mode 100755 index 000000000..4a961cc1c --- /dev/null +++ b/scripts/dotly/create @@ -0,0 +1,99 @@ +#!/usr/bin/env bash + +. "$DOTLY_PATH/scripts/core/_main.sh" +. "$DOTLY_PATH/scripts/core/templating.sh" + +SCRIPT_NAME="dot dotly create" +SCRIPT_VERSION="1.0.0" +SCRIPT_TEMPLATE="$DOTLY_PATH/scripts/dotly/helpers/script-template" + +##? Dotly script creator +##? +##? +##? Usage: +##? create [-h | --help] +##? create [-v | --version] +##? create [-c | --core] [-s | --sample] [...] +##? +##? Options: +##? -h --help Show this help +##? -v --version Show the program version +##? -s --sample Create a script using more complete example with some comments. +##? useful if it is your first script. Anyway you can see more help +##? in the docopt website: http://docopt.org +##? -c --core Create the context and script in "$DOTLY_PATH/scripts" instead of +##? your "$DOTFILES_PATH/scripts" folder +##? +##? Author: +##? Gabriel Trabanco +##? +docs::parse "$@" + +# Print name and version +if ${version:-}; then + output::write "$SCRIPT_NAME v$SCRIPT_VERSION" + exit +fi + +if [[ -z "${context:-}" ]] || [[ -z "${script_name:-}" ]]; then + output::error "You should provide a context and script name" + output::write "Use: $0 -h" + exit 1 +fi + +# Path variables +if ${core:-}; then + output::empty_line + output::write "\033[0;31m\033[1m ALERT!!!!!" + output::write "Create this script in your DOTLY scripts folder could be very dangerous." + output::write "This is an option thinked only for DOTLY devs.\033[0m" + output::empty_line + output::yesno "Are you sure you still want to coninue" "N" || { output::answer "User aborted" && exit 1; } + + script_path="$DOTLY_PATH/scripts/$context" +else + script_path="$DOTFILES_PATH/scripts/$context" +fi + +script_filepath="$script_path/$script_name" + +# Which template to use +if ${sample:-}; then + SCRIPT_TEMPLATE="$SCRIPT_TEMPLATE-more" +fi + +# Create the script context (folder) +mkdir -p "$script_path" + +if [[ -d "$DOTFILES_PATH/scripts/$context" ]]; then + output::solution "$script_path were created or exists previously" +fi + +# If script exits ask user to overwrite +if [[ -f $script_filepath ]]; then + output::yesno "The script exists, do you want to delete it and create a empty script" "N" ||\ + { + output::error "The script name \"$script_name\" exists in context \"$context\" and user refuse to recreate the script" &&\ + output::write "Provide a different name for the script or context." &&\ + exit 1 + } +fi + +# Variables for the script +author="$(git config --global --get user.name)" +email="$(git config --global --get user.email)" +description="${script_description[*]:-}" + +# Description can not be empty +[[ -z "$description" ]] && output::question "Description can not be empty, describe your script" "description" + +cp "$SCRIPT_TEMPLATE" "$script_filepath" +templating::replace "$script_filepath" --script-name="$script_name" --script-context="$context" --script-author="$author" --script-author-email="$email" --script-description="$description" > /dev/null +chmod u+x "$script_filepath" + +output::empty_line +output::solution "The script '$script_name' where successfully created." +output::write "" +output::write "You can access the scipt with your favorite editor by executing:" +output::write "\$EDITOR \"\$DOTFILES_PATH/scripts/$context/$script_name\"" +output::empty_line \ No newline at end of file diff --git a/scripts/dotly/helpers/script-template b/scripts/dotly/helpers/script-template new file mode 100644 index 000000000..531ef65a1 --- /dev/null +++ b/scripts/dotly/helpers/script-template @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +[[ -z "$DOTLY_PATH" ]] && exit 1 + +. "$DOTLY_PATH/scripts/core/_main.sh" + +##? XXX_SCRIPT_DESCRIPTION_XXX +##? +##? +##? Usage: +##? XXX_SCRIPT_NAME_XXX [-h | --help] +##? XXX_SCRIPT_NAME_XXX [-v | --version] +##? +##? Options: +##? -h --help Show this help +##? -v --version Show the program version +##? +##? Author: +##? XXX_SCRIPT_AUTHOR_XXX +docs::parse "$@" + +SCRIPT_NAME="dot XXX_SCRIPT_CONTEXT_XXX XXX_SCRIPT_NAME_XXX" +SCRIPT_VERSION="1.0.0" + +# Print name and version +if ${version:-}; then + output::write "$SCRIPT_NAME v$SCRIPT_VERSION" + exit +fi + +# Here begin your script + +case $1 in +# Any subcommand should be here +*) + exit 1 + ;; +esac \ No newline at end of file diff --git a/scripts/dotly/helpers/script-template-more b/scripts/dotly/helpers/script-template-more new file mode 100644 index 000000000..8077e265e --- /dev/null +++ b/scripts/dotly/helpers/script-template-more @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +[[ -z "$DOTLY_PATH" ]] && exit 1 + +. "$DOTLY_PATH/scripts/core/_main.sh" + +##? XXX_SCRIPT_DESCRIPTION_XXX +##? +##? +##? Usage: +##? XXX_SCRIPT_NAME_XXX [-h | --help] +##? XXX_SCRIPT_NAME_XXX [-v | --version] +##? XXX_SCRIPT_NAME_XXX -c | --custom-option +##? XXX_SCRIPT_NAME_XXX subcommand [...] +##? +##? Options: +##? -h --help Show this help +##? -v --version Show the program version +##? -c --custom-option With two or more spaces you can add some help +##? subcomand [...] Also provide a help with subcommand +##? This text will be printed as well when you call -h or --help option +##? +##? Author: +##? XXX_SCRIPT_AUTHOR_XXX + +# Options part its important because assign short and long version of the params +docs::parse "$@" + +SCRIPT_NAME="dot XXX_SCRIPT_CONTEXT_XXX XXX_SCRIPT_NAME_XXX" +SCRIPT_VERSION="1.0.0" + +# Print name and version +if ${version:-}; then + output::write "$SCRIPT_NAME v$SCRIPT_VERSION" + exit +fi + +# Here begin your script + +case $1 in +"subcommand") + echo "This case is optional and only useful if you want to implement subcommands" + echo "The example repeteable variable value is \"${example_variable[*]:-No value provided}\"" + echo "The optional variable value is \"${example_optional_variable:-No value provided}\"" + ;; +*) + exit 1 + ;; +esac \ No newline at end of file diff --git a/scripts/dotly/install-remote b/scripts/dotly/install-remote new file mode 100755 index 000000000..beccbe0c3 --- /dev/null +++ b/scripts/dotly/install-remote @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +source "$DOTLY_PATH/scripts/core/_main.sh" + +SCRIPT_NAME="dot dotly install-remote" +SCRIPT_VERSION="1.0.0" + +# Save current working directory to return user there +STARTING_DIRECTORY="$(pwd)" +CURL_BIN="$(which curl)" + +##? Install remote context or script in your $DOTFILES_PATH from url. It +##? must be the url to the raw file. +##? If you fill the last param , the remote file name will be +##? omited and renamed in your $DOTFILES_PATH/scripts/ folder +##? +##? Usage: +##? install-remote [ -h | --help ] +##? install-remote [ -v | --version ] +##? install-remote [] +##? +##? Options: +##? -h --help Show this help +##? -v --version Show the program version +##? +##? +##? Author: +##? Gabriel Trabanco Llano +docs::parse "$@" + +# Print name and version +if $version; then + output::write "$SCRIPT_NAME v$SCRIPT_VERSION" + exit +fi + +# Script name if provided if not with downloaded name +[[ -n $script_name ]] && script_name_args="-o $script_name" || script_name_args=${script_name:-"-O"} + +# Download command +download_command="$CURL_BIN -k -L -f -q $script_name_args" + +# Scripts context directory +dotfiles_context="$DOTFILES_PATH/scripts/$context" + +# Create context directory and move to it +mkdir -p "$dotfiles_context" +cd "$dotfiles_context" + +# Download the script +output::write "Downloading the script ⚡️" +$(echo "$download_command" "$script_raw_url") +if [ ! $? ] ; then + if [ ! $(ls -A "$dotfiles_context") ]; then + output::answer "El context $dotfiles_context esta vacio" + fi +fi + +# Getting the name +script_name="$(ls -Art | tail -n 1)" + +# Applying execution rights +chmod u+x "$dotfiles_context/$script_name" + +# How to use it :) +echo +output::solution "The script was successfully added 😀" +output::write "You can execute the script now with:" +output::write "dot $context $script_name" + +cd "$STARTING_DIRECTORY" \ No newline at end of file