From b395cd557cdf008b89bd55f73ee3b6aac14039bc Mon Sep 17 00:00:00 2001 From: Bhavi Dhingra Date: Tue, 5 Oct 2021 04:33:52 +0530 Subject: [PATCH 1/2] refactor: clean up main branch --- _config.yml | 10 - _layouts/default.html | 67 ------- install | 327 --------------------------------- try | 306 ------------------------------- uninstall | 303 ------------------------------ update | 417 ------------------------------------------ 6 files changed, 1430 deletions(-) delete mode 100644 _config.yml delete mode 100644 _layouts/default.html delete mode 100755 install delete mode 100755 try delete mode 100644 uninstall delete mode 100644 update diff --git a/_config.yml b/_config.yml deleted file mode 100644 index ee77bae..0000000 --- a/_config.yml +++ /dev/null @@ -1,10 +0,0 @@ -title: custom-git -description: An open source, general-purpose, highly efficient command line git tool. -show_downloads: false -google_analytics: UA-184167407-3 -theme: jekyll-theme-leap-day -github: - repository_url: https://github.com/custom-git/custom-git-bash - is_project_page: true - owner_url: https://bhavidhingra.dev - owner_name: bhavidhingra diff --git a/_layouts/default.html b/_layouts/default.html deleted file mode 100644 index f2479ad..0000000 --- a/_layouts/default.html +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - -{% seo %} - - - - - - - - - - -
-

{{ page.title | default: site.title | default: site.github.repository_name }}

-

{{ page.description | default: site.description | default: site.github.project_tagline }}

-
- - - -
- -
- {{ content }} - -
- -
- - {% if site.google_analytics %} - - {% endif %} - - diff --git a/install b/install deleted file mode 100755 index 9d446f8..0000000 --- a/install +++ /dev/null @@ -1,327 +0,0 @@ -#!/bin/bash - -#shellcheck disable=SC2184 # Quote arguments to unset so they're not glob expanded -#shellcheck disable=SC2088 # Tilde does not expand in quotes. Use $HOME -#shellcheck disable=SC2053 # Quote the right-hand side of != in [[ ]] to prevent glob matching -#shellcheck disable=SC2091 # Remove surrounding $() to avoid executing output (or use eval if intentional) -#shellcheck disable=SC2086 # Double quote to prevent globbing and word splitting -#shellcheck disable=SC2120 # mucl references arguments, but none are ever passed - -################## -# util functions # -################## - -SUCCESS=0 -FAILURE=1 - -MOVE_UP=$(tput cuu 1) -CLEAR_LINE=$(tput el 1) - -function mucl() { - if [[ $# -eq 0 ]]; then - numIterations=1 - else - numIterations=${1} - fi - for (( i = 0; i < numIterations; i++)); do - echo "${MOVE_UP}${CLEAR_LINE}${MOVE_UP}" - done -} - -currDir="$(pwd)" - -function apply_tput() { - - case "${1}" in - black) tput setaf 0 - ;; - red) tput setaf 1 - ;; - green) tput setaf 2 - ;; - yellow) tput setaf 3 - ;; - blue) tput setaf 4 - ;; - magenta) tput setaf 5 - ;; - cyan) tput setaf 6 - ;; - white) tput setaf 7 - ;; - reset) tput sgr0 - ;; - *) tput "${1}" - ;; - esac -} - -# Usage: insert_new_lines 3 -function insert_new_lines() { - for (( i = 0; i < ${1}; i++)); do - echo - done -} - -# Usage: banner_color 1 "red" "*" "my title" 2 -function banner_color() { - insert_new_lines ${1} - - apply_tput "${2}" - apply_tput bold - - local msg="${3} ${4} ${3}" - local edge - edge=${msg//?/$3} - echo "${edge}" - echo "${msg}" - printf "%s" "${edge}" - - apply_tput reset - - insert_new_lines ${5} -} - -# Usage: banner_color_err 1 "error msg" 2 -function banner_color_err() { - banner_color ${1} "red" "~" "[ERROR] ${2}" ${3} -} - -# Usage: print_as 3 "blue" "msg" 1 -function print_as() { - insert_new_lines ${1}; shift - - while [[ $# -gt 2 ]]; do - apply_tput "${1}"; shift - done - local msg="${1}"; shift - printf "%s" "${msg}" - apply_tput reset - - insert_new_lines ${1}; -} - -# Usage: print_info 3 "msg" 2 -function print_info() { - print_as ${1} "blue" "${2}" ${3} -} - -# Usage: print_err 3 "msg" 2 -function print_err() { - print_as ${1} "red" "${2}" ${3} -} - -function is_command_installed() { - - if command -v "${1}" &>/dev/null; then - echo true - else - echo false - fi -} - -function append_line() { - set -e - - local line="${1}" file="${2}" pat="${3:-}" lno="" - - if [ -f "$file" ]; then - if [ $# -lt 4 ]; then - lno=$(grep -nF "$line" "$file" | sed 's/:.*//' | tr '\n' ' ') - else - lno=$(grep -nF "$pat" "$file" | sed 's/:.*//' | tr '\n' ' ') - fi - fi - if [ -z "$lno" ]; then - [ -f "$file" ] && echo >> "$file" - echo "$line" >> "$file" - fi - set +e -} - -# Usage: assert_equal A B msg -function assert_equal() { - - local A="${1}" B="${2}" msg="${3}" - [[ "${A}" != "${B}" ]] && { - mucl - banner_color_err 0 "${msg}" 2 - exit ${FAILURE} - } -} - -# Usage: assert_success msg -function assert_success() { - - local status="$?" msg="${1}" - assert_equal "${status}" ${SUCCESS} "${msg}" -} - -function get_latest_annotated_tag() { - git describe --abbrev=0 &> /dev/null - if [[ $? -ne ${SUCCESS} ]]; then - echo "" - return - fi - git describe --abbrev=0 -} - -function install_clipboard() { - - if ! $(is_command_installed "npm"); then - banner_color_err 1 "npm not installed." 2 - return ${FAILURE} - fi - print_info 0 "Installing clipboard-cli ..." 1 - sudo npm install -g clipboard-cli &> /dev/null - if (( $? != SUCCESS )); then - mucl 2 - banner_color_err 0 "clipboard-cli installation failed." 2 - return ${FAILURE} - fi - - mucl 2 - banner_color 0 "magenta" "*" "clipboard-cli installed." 2 -} - -function install_fzf() { - - print_info 0 "Installing fzf ..." 1 - - git clone --depth 1 https://github.com/junegunn/fzf.git "${FZF_HOME}" &> /dev/null - if (( $? != SUCCESS )); then - mucl - banner_color_err 0 "Fetching fzf failed. Please check your network." 2 - return ${FAILURE} - fi - - cd "${FZF_HOME}" || { - mucl - banner_color_err 0 "couldn't enter directory: ${FZF_HOME}" 2 - return ${FAILURE} - } - ./install --all &> /dev/null - - if (( $? != SUCCESS )); then - mucl - banner_color_err 0 "fzf installation failed." 2 - return ${FAILURE} - fi - - mucl - banner_color 0 "magenta" "*" "fzf installed." 2 -} - -function finish { - cd "${currDir}" || { - banner_color_err 0 "couldn't enter directory: ${currDir}" 2 - exit ${FAILURE} - } -} -trap finish EXIT - -##################### -# Enable custom-git # -##################### - -insert_new_lines 1 - -shells=("bash" "zsh") -numShells=${#shells[@]} - -for ((i = 0 ; i < numShells ; i++)); do - shell="${shells[$i]}" - if ! $(is_command_installed "${shell}"); then - unset shells[$i] - fi -done - -if [[ ${#shells[@]} -eq 0 ]]; then - print_err 0 "custom-git is only supported for bash and zsh shells. Stopping installation." 2 - exit ${FAILURE} -fi - -prefix='~/.custom-git' - -CUSTOM_GIT_HOME="${HOME}"/.custom-git -FZF_HOME="${HOME}"/.fzf -CUSTOM_GIT_BASH_REPO_URL="https://github.com/custom-git/custom-git-bash" -CUSTOM_GIT_CLONE_URL="${CUSTOM_GIT_BASH_REPO_URL}.git" -CUSTOM_GIT_WEBSITE_URL="https://custom-git.io" - -if ! $(is_command_installed "clipboard"); then - - install_clipboard - if (( $? != SUCCESS )); then - print_info 0 "Please install clipboard-cli from " 0 - print_as 0 "magenta" "bold" "\"https://github.com/sindresorhus/clipboard-cli\"" 1 - print_info 0 "Otherwise, some custom-git commands may not work correctly." 2 - fi -fi - -if ! $(is_command_installed "fzf"); then - - install_fzf - if (( $? != SUCCESS )); then - print_info 0 "Please install fzf from " 0 - print_as 0 "magenta" "bold" "https://github.com/junegunn/fzf#installation" 1 - print_as 0 "blue" "and try again..." 2 - exit ${FAILURE} - fi -fi - -if [[ -d "${CUSTOM_GIT_HOME}" ]]; then - print_info 0 "custom-git is already installed on your system." 2 - exit ${SUCCESS} -fi - -print_info 0 "Installing custom-git..." 1 -git clone --recurse-submodules "${CUSTOM_GIT_CLONE_URL}" "${CUSTOM_GIT_HOME}" &> /dev/null -assert_success "Fetching custom-git failed. Please check your network." - -if [[ ! -d "${CUSTOM_GIT_HOME}" ]]; then - mucl - banner_color_err 0 "$(printf "Couldn't create the directory %s. Exiting." "${prefix}")" 2 - exit ${FAILURE} -fi - -cd "${CUSTOM_GIT_HOME}" || { - banner_color_err 0 "couldn't enter directory: ${CUSTOM_GIT_HOME}" 2 - exit ${FAILURE} -} - -latestVersion="$(get_latest_annotated_tag)" -git checkout "${latestVersion}" &> /dev/null -git submodule update --init --recursive &> /dev/null -assert_success "Submodule update failed. Please check your network." - -for shell in "${shells[@]}"; do - [ $shell = zsh ] && dest=${ZDOTDIR:-~}/.zshrc || dest=~/.bashrc - append_line "[ -f ${prefix}/init.${shell} ] && source ${prefix}/init.${shell}" "$dest" "source ${prefix}/init.${shell}" -done - -mucl -print_info 0 "For more details, visit: " 0 -print_as 0 "magenta" "bold" "${CUSTOM_GIT_WEBSITE_URL}" 2 - -banner_color 0 "magenta" "*" "Installation complete - custom-git ${latestVersion}" 2 - -print_info 0 "Restart your shell or reload config file." 1 -for shell in "${shells[@]}"; do - case "${shell}" in - bash) - printf " source ~/.bashrc # bash" - archi=$(uname -sm) - [[ "$archi" =~ Darwin ]] && printf " (~/.bashrc should be sourced from ~/.bash_profile)" - echo - ;; - zsh) - echo " source ${ZDOTDIR:-~}/.zshrc # zsh" - ;; - *) - printf "\n %s shell is not supported.\n" "${shell}" - ;; - esac -done - -echo \ No newline at end of file diff --git a/try b/try deleted file mode 100755 index e2e5d55..0000000 --- a/try +++ /dev/null @@ -1,306 +0,0 @@ -#!/bin/bash - -#shellcheck disable=SC2184 # Quote arguments to unset so they're not glob expanded. -#shellcheck disable=SC2088 # Tilde does not expand in quotes. Use $HOME. -#shellcheck disable=SC2053 # Quote the right-hand side of != in [[ ]] to prevent glob matching. -#shellcheck disable=SC2091 # Remove surrounding $() to avoid executing output (or use eval if intentional). -#shellcheck disable=SC2164 # Use 'cd ... || exit' or 'cd ... || return' in case cd fails. -#shellcheck disable=SC2120 # references arguments, but none are ever passed. -#shellcheck disable=SC2086 # Double quote to prevent globbing and word splitting. - -################## -# util functions # -################## - -[ -f "$HOME"/.custom-git.try ] && rm "$HOME"/.custom-git.try - -__CG_MOVE_UP=$(tput cuu 1) -__CG_CLEAR_LINE=$(tput el 1) -alias __CG_MUCL='echo ${__CG_MOVE_UP}${__CG_CLEAR_LINE}${__CG_MOVE_UP}' - -function __cg_apply_tput() { - - case "${1}" in - black) tput setaf 0 - ;; - red) tput setaf 1 - ;; - green) tput setaf 2 - ;; - yellow) tput setaf 3 - ;; - blue) tput setaf 4 - ;; - magenta) tput setaf 5 - ;; - cyan) tput setaf 6 - ;; - white) tput setaf 7 - ;; - reset) tput sgr0 - ;; - *) tput "${1}" - ;; - esac -} - -# Usage: __cg_insert_new_lines 3 -function __cg_insert_new_lines() { - for (( i = 0; i < ${1}; i++)); do - echo - done -} - -# Usage: __cg_banner_color 1 "red" "*" "my title" 2 -function __cg_banner_color() { - __cg_insert_new_lines ${1} - - __cg_apply_tput "${2}" - __cg_apply_tput bold - - local msg="${3} ${4} ${3}" - local edge - edge=${msg//?/$3} - echo "${edge}" - echo "${msg}" - printf "%s" "${edge}" - - __cg_apply_tput reset - - __cg_insert_new_lines ${5} -} - -# Usage: __cg_banner_color_err 1 "error msg" 2 -function __cg_banner_color_err() { - __cg_banner_color ${1} "red" "~" "[ERROR] ${2}" ${3} -} - -# Usage: __cg_print_as 3 "blue" "msg" 1 -function __cg_print_as() { - __cg_insert_new_lines ${1}; shift - - while [[ $# -gt 2 ]]; do - __cg_apply_tput "${1}"; shift - done - local msg="${1}"; shift - printf "%s" "${msg}" - __cg_apply_tput reset - - __cg_insert_new_lines ${1}; -} - -# Usage: __cg_print_info 3 "msg" 2 -function __cg_print_info() { - __cg_print_as ${1} "blue" "[INFO] ${2}" ${3} -} - -# Usage: __cg_print_err 3 "msg" 2 -function __cg_print_err() { - __cg_print_as ${1} "red" "[ERROR] ${2}" ${3} -} - -function __cg_is_command_installed() { - - if command -v "${1}" &>/dev/null; then - echo true - else - echo false - fi -} - -########################### -# Enable custom-git trial # -########################### - -__cg_insert_new_lines 1 - -__cg_shells=("bash" "zsh") -__cg_shellsNotFound=0 - -for shell in "${__cg_shells[@]}"; do - if ! command -v "$shell" > /dev/null; then - __cg_shellsNotFound=$((__cg_shellsNotFound + 1)) - fi -done - -if [[ ${#__cg_shells[@]} -eq $__cg_shellsNotFound ]]; then - __cg_print_err 0 "custom-git is only supported for bash and zsh shells. Stopping installation." 2 - return -fi - -__CG_SUCCESS=0 -__CG_FAILURE=1 -__cg_prefix='~/.custom-git' -__cg_currDir="$(pwd)" -__cg_restart_shell=false - -export CUSTOM_GIT_HOME="$HOME"/.custom-git-trial -export CUSTOM_CONSOLE_HOME="$CUSTOM_GIT_HOME"/custom-console-bash - -function __cg_install_clipboard() { - - __cg_clipboard_installation_status=$__CG_SUCCESS - - if ! $(__cg_is_command_installed "npm"); then - __cg_clipboard_installation_status=$__CG_FAILURE - __cg_banner_color_err 1 "npm not installed." 2 - return - fi - __cg_print_info 1 "Installing clipboard-cli ..." 1 - sudo npm install -g clipboard-cli &> /dev/null - - if (( $? != __CG_SUCCESS )); then - __cg_clipboard_installation_status=$__CG_FAILURE - __CG_MUCL - __cg_banner_color_err 0 "clipboard-cli installation failed." 2 - return - fi - - __CG_MUCL - __cg_banner_color 0 "magenta" "*" "clipboard-cli installed." 2 -} - -if ! $(__cg_is_command_installed "clipboard"); then - - __cg_print_info 0 "Some custom-git commands use " 0 - __cg_print_as 0 "magenta" "bold" "clipboard-cli " 1 - __cg_print_as 0 "blue" "Allow me to install it on your system? (y/n) : " 0 - - read -r - if [[ "$REPLY" != "y" ]]; then - __cg_print_info 1 "Please install clipboard-cli from " 0 - __cg_print_as 0 "magenta" "bold" "\"https://github.com/sindresorhus/clipboard-cli\"" 1 - __cg_print_info 0 "Some custom-git commands may not work correctly." 2 - else - __cg_install_clipboard - if [[ $__cg_clipboard_installation_status -eq $__CG_FAILURE ]]; then - __cg_print_info 0 "Please install clipboard-cli from " 0 - __cg_print_as 0 "magenta" "bold" "\"https://github.com/sindresorhus/clipboard-cli\"" 1 - __cg_print_info 0 "Some custom-git commands may not work correctly." 2 - fi - fi -fi - -function __cg_install_fzf() { - - __cg_print_info 1 "Installing fzf ..." 1 - - __cg_fzf_installation_status=$__CG_SUCCESS - git clone --depth 1 https://github.com/junegunn/fzf.git "$HOME"/.fzf &> /dev/null - cd "$HOME"/.fzf || { - __cg_fzf_installation_status=$__CG_FAILURE - __CG_MUCL - __cg_banner_color_err 0 "couldn't enter directory: $HOME/.fzf" 2 - return - } - ./install --all &> /dev/null - - if (( $? != __CG_SUCCESS )); then - __cg_fzf_installation_status=$__CG_FAILURE - __CG_MUCL - __cg_banner_color_err 0 "fzf installation failed." 2 - return - fi - - __CG_MUCL - __cg_banner_color 0 "magenta" "*" "fzf installed (restart your shell)" 2 - - __cg_restart_shell=true - - cd "$__cg_currDir" || { - __cg_banner_color_err 0 "couldn't enter directory: $__cg_currDir" 2 - return - } -} - -if ! $(__cg_is_command_installed "fzf"); then - - __cg_print_info 0 "custom-git requires " 0 - __cg_print_as 0 "magenta" "bold" "fzf (fuzzy finder)" 0 - __cg_print_as 0 "blue" " to work." 1 - __cg_print_as 0 "blue" "Allow me to install it on your system? (y/n) : " 0 - - read -r - if [[ "$REPLY" != "y" ]]; then - __cg_print_info 1 "Please install fzf from " 0 - __cg_print_as 0 "magenta" "bold" "https://github.com/junegunn/fzf#installation" 1 - __cg_print_as 0 "blue" "and try again..." 2 - return - fi - - __cg_install_fzf - if [[ $__cg_fzf_installation_status -eq $__CG_FAILURE ]]; then - __cg_print_info 0 "Please install fzf from " 0 - __cg_print_as 0 "magenta" "bold" "https://github.com/junegunn/fzf#installation" 1 - __cg_print_as 0 "blue" "and try again..." 2 - return - fi -fi - -if $__cg_restart_shell; then - - __cg_print_info 0 "After shell restart, run the 'try' command again." 1 - printf ' -if command -v curl &>/dev/null; then - curl -fsSL -o ~/.custom-git.try https://custom-git.io/try - source ~/.custom-git.try -else - wget -q -O ~/.custom-git.try https://custom-git.io/try - source ~/.custom-git.try -fi - -' - return -fi - -if [[ -d "$CUSTOM_GIT_HOME" ]]; then - cd "${CUSTOM_GIT_HOME}" - git switch integ &> /dev/null - __cg_print_info 0 "Fetching latest integ branch of custom-git" 1 - git pull &> /dev/null - - if (( $? != __CG_SUCCESS )); then - __CG_MUCL - __cg_banner_color_err 0 "Some error occurred while fetching custom-git. Please check your network." 2 - cd "$__cg_currDir" || __cg_banner_color_err 1 "couldn't enter directory: $__cg_currDir" 2 - return - fi - - cd "$__cg_currDir" || __cg_banner_color_err 1 "couldn't enter directory: $__cg_currDir" 2 - -else - - __cg_print_info 0 "Enabling custom-git commands..." 1 - git clone --recurse-submodules --single-branch --branch integ\ - https://github.com/custom-git/custom-git-bash.git "$CUSTOM_GIT_HOME" &> /dev/null - - if (( $? != __CG_SUCCESS )); then - __CG_MUCL - __cg_banner_color_err 0 "Some error occurred while fetching custom-git. Please check your network." 2 - return - fi - - if [[ ! -d "$CUSTOM_GIT_HOME" ]]; then - __CG_MUCL - __cg_banner_color_err 0 "$(printf "Couldn't create the directory %s. Exiting." "$__cg_prefix")" 2 - return - fi -fi - -export __CUSTOM_GIT_UTIL="$CUSTOM_GIT_HOME"/util -export __CUSTOM_CONSOLE_UTIL="$CUSTOM_CONSOLE_HOME"/util - -if [[ ! "$PATH" == *$CUSTOM_CONSOLE_HOME/cmd* ]]; then - export PATH="$CUSTOM_CONSOLE_HOME/cmd${PATH:+:${PATH}}" -fi -if [[ ! "$PATH" == *$CUSTOM_GIT_HOME/cmd* ]]; then - export PATH="$CUSTOM_GIT_HOME/cmd${PATH:+:${PATH}}" -fi - -export FZF_DEFAULT_OPTS="--reverse --border --ansi --preview-window wrap:down:70% --tabstop=4" -export FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS} --color='preview-fg:-1'" - -__CG_MUCL -__cg_banner_color 0 "magenta" "*" "All the custom-git commands are enabled for this shell session. Existing installation won't be affected." 2 -__cg_print_info 0 "For more details, visit: " 0 -__cg_print_as 0 "magenta" "bold" "https://github.com/custom-git/custom-git-bash" 2 diff --git a/uninstall b/uninstall deleted file mode 100644 index 67ed108..0000000 --- a/uninstall +++ /dev/null @@ -1,303 +0,0 @@ -#!/bin/bash - -#shellcheck disable=SC2184 # Quote arguments to unset so they're not glob expanded. -#shellcheck disable=SC2088 # Tilde does not expand in quotes. Use $HOME. -#shellcheck disable=SC2053 # Quote the right-hand side of != in [[ ]] to prevent glob matching. -#shellcheck disable=SC2091 # Remove surrounding $() to avoid executing output (or use eval if intentional). -#shellcheck disable=SC2086 # Double quote to prevent globbing and word splitting. -#shellcheck disable=SC2181 # Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. - -################## -# util functions # -################## - -SUCCESS=0 -FAILURE=1 - -MOVE_UP=$(tput cuu 1) -CLEAR_LINE=$(tput el 1) - -function mucl() { - echo "${MOVE_UP}${CLEAR_LINE}${MOVE_UP}" -} - -currDir="$(pwd)" - -function apply_tput() { - - case "${1}" in - black) tput setaf 0 - ;; - red) tput setaf 1 - ;; - green) tput setaf 2 - ;; - yellow) tput setaf 3 - ;; - blue) tput setaf 4 - ;; - magenta) tput setaf 5 - ;; - cyan) tput setaf 6 - ;; - white) tput setaf 7 - ;; - reset) tput sgr0 - ;; - *) tput "${1}" - ;; - esac -} - -# Usage: insert_new_lines 3 -function insert_new_lines() { - for (( i = 0; i < ${1}; i++)); do - echo - done -} - -# Usage: banner_color 1 "red" "*" "my title" 2 -function banner_color() { - insert_new_lines ${1} - - apply_tput "${2}" - apply_tput bold - - local msg="${3} ${4} ${3}" - local edge - edge=${msg//?/$3} - echo "${edge}" - echo "${msg}" - printf "%s" "${edge}" - - apply_tput reset - - insert_new_lines ${5} -} - -# Usage: banner_color_err 1 "error msg" 2 -function banner_color_err() { - banner_color ${1} "red" "~" "[ERROR] ${2}" ${3} -} - -# Usage: print_as 3 "blue" "msg" 1 -function print_as() { - insert_new_lines ${1}; shift - - while [[ $# -gt 2 ]]; do - apply_tput "${1}"; shift - done - local msg="${1}"; shift - printf "%s" "${msg}" - apply_tput reset - - insert_new_lines ${1}; -} - -# Usage: print_info 3 "msg" 2 -function print_info() { - print_as ${1} "blue" "${2}" ${3} -} - -# Usage: print_err 3 "msg" 2 -function print_err() { - print_as ${1} "red" "${2}" ${3} -} - -function is_command_installed() { - - if command -v "${1}" &>/dev/null; then - echo true - else - echo false - fi -} - -function ask() { - while true; do - read -p "$1 ([y]/n) " -r - REPLY=${REPLY:-"y"} - if [[ $REPLY =~ ^[Yy]$ ]]; then - return 0 - elif [[ $REPLY =~ ^[Nn]$ ]]; then - return 1 - fi - done -} - -function append_line() { - set -e - - local line="${1}" file="${2}" pat="${3:-}" lno="" - - if [ -f "$file" ]; then - if [ $# -lt 4 ]; then - lno=$(grep -nF "$line" "$file" | sed 's/:.*//' | tr '\n' ' ') - else - lno=$(grep -nF "$pat" "$file" | sed 's/:.*//' | tr '\n' ' ') - fi - fi - if [ -z "$lno" ]; then - [ -f "$file" ] && echo >> "$file" - echo "$line" >> "$file" - fi - set +e -} - -function remove_file() { - local file="${1}" - [ -f "${file}" ] && { - print_info 0 "Remove ${file}" 1 - rm -f "${file}" - } -} - -function remove_dir() { - local dir="${1}" - [ -d "${dir}" ] && { - print_info 0 "Remove ${dir}" 1 - rm -rf "${dir}" - } -} - -function remove_line() { - src=$(readlink "$1") - if [ $? -eq 0 ]; then - print_info 0 "Remove from ${1} ($src):" 1 - else - src=$1 - print_info 0 "Remove from ${1}:" 1 - fi - - shift - line_no=1 - match=0 - while [ -n "$1" ]; do - line=$(sed -n "$line_no,\$p" "$src" | \grep -m1 -nF "$1") - if [ $? -ne 0 ]; then - shift - line_no=1 - continue - fi - line_no=$(( $(sed 's/:.*//' <<< "$line") + line_no - 1 )) - content=$(sed 's/^[0-9]*://' <<< "$line") - match=1 - echo " - Line #$line_no: $content" - [ "$content" = "$1" ] || ask " - Remove?" - if [ $? -eq 0 ]; then - awk -v n=$line_no 'NR == n {next} {print}' "$src" > "$src.bak" && - mv "$src.bak" "$src" || break - echo " - Removed" - else - echo " - Skipped" - line_no=$(( line_no + 1 )) - fi - done - [ $match -eq 0 ] && echo " - Nothing found" - echo -} - -# Usage: assert_equal A B msg -function assert_equal() { - - local A="${1}" B="${2}" msg="${3}" - [[ "${A}" != "${B}" ]] && { - mucl - banner_color_err 0 "${msg}" 2 - exit ${FAILURE} - } -} - -# Usage: assert_success msg -function assert_success() { - - local status="$?" msg="${1}" - assert_equal "${status}" ${SUCCESS} "${msg}" -} - -function get_latest_annotated_tag() { - git describe --abbrev=0 &> /dev/null - if [[ $? -ne ${SUCCESS} ]]; then - echo "" - return - fi - git describe --abbrev=0 -} - -function finish { - cd "${currDir}" || { - banner_color_err 0 "couldn't enter directory: ${currDir}" 2 - exit ${FAILURE} - } -} -trap finish EXIT - -######################## -# Uninstall custom-git # -######################## - -insert_new_lines 1 - -CUSTOM_GIT_HOME="${HOME}"/.custom-git - -if [[ ! -d "${CUSTOM_GIT_HOME}" ]]; then - banner_color_err 0 "custom-git is not installed on your system." 2 - print_info 0 "Visit " 0 - print_as 0 "magenta" "bold" "https://custom-git.io" 0 - print_as 0 "blue" " for more details." 2 - exit ${FAILURE} -fi - -shells=("bash" "zsh") -numShells=${#shells[@]} - -for ((i = 0 ; i < numShells ; i++)); do - shell="${shells[$i]}" - if ! $(is_command_installed "${shell}"); then - unset shells[$i] - fi -done - -if [[ ${#shells[@]} -eq 0 ]]; then - banner_color_err 0 "custom-git is only supported for bash and zsh shells. Stopping uninstallation." 2 - print_info 0 "Visit " 0 - print_as 0 "magenta" "bold" "https://custom-git.io" 0 - print_as 0 "blue" " for more information." 2 - exit ${FAILURE} -fi - -prefix='~/.custom-git' -CUSTOM_GIT_WEBSITE_URL="https://custom-git.io" - -cd "${CUSTOM_GIT_HOME}" || { - banner_color_err 0 "couldn't enter directory: ${CUSTOM_GIT_HOME}" 2 - exit ${FAILURE} -} - -currVersion="$(get_latest_annotated_tag)" -if [[ "${currVersion}" == "" || "${currVersion}" == "v0.1.0" ]]; then - for shell in "${shells[@]}"; do - initFile="${CUSTOM_GIT_HOME}.${shell}" - [ -f "${initFile}" ] && { - remove_file "${initFile}" - remove_line ~/.${shell}rc \ - "[ -f ${prefix}.${shell} ] && source ${prefix}.${shell}" \ - "source ${prefix}.${shell}" - } - done -fi -for shell in "${shells[@]}"; do - initFile="${HOME}/.${shell}rc" - [ -f "${initFile}" ] && { - remove_line ~/.${shell}rc \ - "[ -f ${prefix}/init.${shell} ] && source ${prefix}/init.${shell}" \ - "source ${prefix}/init.${shell}" - } -done - -remove_dir "${CUSTOM_GIT_HOME}" - -print_info 1 "For more details, visit: " 0 -print_as 0 "magenta" "bold" "${CUSTOM_GIT_WEBSITE_URL}" 2 - -banner_color 0 "red" "#" "custom-git uninstalled." 2 diff --git a/update b/update deleted file mode 100644 index f931c7f..0000000 --- a/update +++ /dev/null @@ -1,417 +0,0 @@ -#!/bin/bash - -#shellcheck disable=SC2184 # Quote arguments to unset so they're not glob expanded. -#shellcheck disable=SC2088 # Tilde does not expand in quotes. Use $HOME. -#shellcheck disable=SC2053 # Quote the right-hand side of != in [[ ]] to prevent glob matching. -#shellcheck disable=SC2091 # Remove surrounding $() to avoid executing output (or use eval if intentional). -#shellcheck disable=SC2086 # Double quote to prevent globbing and word splitting. -#shellcheck disable=SC2181 # Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. -#shellcheck disable=SC2119 # Use mucl "$@" if function's $1 should mean script's $1 - -################## -# util functions # -################## - -SUCCESS=0 -FAILURE=1 - -MOVE_UP=$(tput cuu 1) -CLEAR_LINE=$(tput el 1) - -function mucl() { - if [[ $# -eq 0 ]]; then - numIterations=1 - else - numIterations=${1} - fi - for (( i = 0; i < numIterations; i++)); do - echo "${MOVE_UP}${CLEAR_LINE}${MOVE_UP}" - done -} - -currDir="$(pwd)" - -function apply_tput() { - - case "${1}" in - black) tput setaf 0 - ;; - red) tput setaf 1 - ;; - green) tput setaf 2 - ;; - yellow) tput setaf 3 - ;; - blue) tput setaf 4 - ;; - magenta) tput setaf 5 - ;; - cyan) tput setaf 6 - ;; - white) tput setaf 7 - ;; - reset) tput sgr0 - ;; - *) tput "${1}" - ;; - esac -} - -# Usage: insert_new_lines 3 -function insert_new_lines() { - for (( i = 0; i < ${1}; i++)); do - echo - done -} - -# Usage: banner_color 1 "red" "*" "my title" 2 -function banner_color() { - insert_new_lines ${1} - - apply_tput "${2}" - apply_tput bold - - local msg="${3} ${4} ${3}" - local edge - edge=${msg//?/$3} - echo "${edge}" - echo "${msg}" - printf "%s" "${edge}" - - apply_tput reset - - insert_new_lines ${5} -} - -# Usage: banner_color_err 1 "error msg" 2 -function banner_color_err() { - banner_color ${1} "red" "~" "[ERROR] ${2}" ${3} -} - -# Usage: print_as 3 "blue" "msg" 1 -function print_as() { - insert_new_lines ${1}; shift - - while [[ $# -gt 2 ]]; do - apply_tput "${1}"; shift - done - local msg="${1}"; shift - printf "%s" "${msg}" - apply_tput reset - - insert_new_lines ${1}; -} - -# Usage: print_info 3 "msg" 2 -function print_info() { - print_as ${1} "blue" "${2}" ${3} -} - -# Usage: print_err 3 "msg" 2 -function print_err() { - print_as ${1} "red" "${2}" ${3} -} - -function is_command_installed() { - - if command -v "${1}" &>/dev/null; then - echo true - else - echo false - fi -} - -function ask() { - while true; do - read -p "${1} ([y]/n) " -r - REPLY=${REPLY:-"y"} - if [[ $REPLY =~ ^[Yy]$ ]]; then - return 0 - elif [[ $REPLY =~ ^[Nn]$ ]]; then - return 1 - fi - done -} - -function append_line() { - set -e - - local line="${1}" file="${2}" pat="${3:-}" lno="" - - if [ -f "$file" ]; then - if [ $# -lt 4 ]; then - lno=$(grep -nF "$line" "$file" | sed 's/:.*//' | tr '\n' ' ') - else - lno=$(grep -nF "$pat" "$file" | sed 's/:.*//' | tr '\n' ' ') - fi - fi - if [ -z "$lno" ]; then - [ -f "$file" ] && echo >> "$file" - echo "$line" >> "$file" - fi - set +e -} - -function remove_file() { - local file="${1}" - [ -f "${file}" ] && { - print_info 0 "Remove ${file}" 1 - rm -f "${file}" - } -} - -function remove_line() { - src=$(readlink "$1") - if [ $? -eq 0 ]; then - print_info 0 "Remove from ${1} ($src):" 1 - else - src=$1 - print_info 0 "Remove from ${1}:" 1 - fi - - shift - line_no=1 - match=0 - while [ -n "$1" ]; do - line=$(sed -n "$line_no,\$p" "$src" | \grep -m1 -nF "$1") - if [ $? -ne 0 ]; then - shift - line_no=1 - continue - fi - line_no=$(( $(sed 's/:.*//' <<< "$line") + line_no - 1 )) - content=$(sed 's/^[0-9]*://' <<< "$line") - match=1 - echo " - Line #$line_no: $content" - [ "$content" = "$1" ] || ask " - Remove?" - if [ $? -eq 0 ]; then - awk -v n=$line_no 'NR == n {next} {print}' "$src" > "$src.bak" && - mv "$src.bak" "$src" || break - echo " - Removed" - else - echo " - Skipped" - line_no=$(( line_no + 1 )) - fi - done - [ $match -eq 0 ] && echo " - Nothing found" - echo -} - -# Usage: assert_equal A B msg -function assert_equal() { - - local A="${1}" B="${2}" msg="${3}" - [[ "${A}" != "${B}" ]] && { - mucl - banner_color_err 0 "${msg}" 2 - exit ${FAILURE} - } -} - -# Usage: assert_success msg -function assert_success() { - - local status="$?" msg="${1}" - assert_equal "${status}" ${SUCCESS} "${msg}" -} - -function get_latest_annotated_tag() { - git describe --abbrev=0 &> /dev/null - if [[ $? -ne ${SUCCESS} ]]; then - echo "" - return - fi - git describe --abbrev=0 -} - -function install_clipboard() { - - if ! $(is_command_installed "npm"); then - banner_color_err 1 "npm not installed." 2 - return ${FAILURE} - fi - - print_info 0 "Installing clipboard-cli ..." 1 - sudo npm install -g clipboard-cli &> /dev/null - - if (( $? != SUCCESS )); then - mucl 2 - banner_color_err 0 "clipboard-cli installation failed." 2 - return ${FAILURE} - fi - - mucl 2 - banner_color 0 "magenta" "*" "clipboard-cli installed." 2 -} - -function install_fzf() { - - print_info 0 "Installing fzf ..." 1 - - git clone --depth 1 https://github.com/junegunn/fzf.git "${FZF_HOME}" &> /dev/null - if (( $? != SUCCESS )); then - mucl - banner_color_err 0 "Fetching fzf failed. Please check your network." 2 - return ${FAILURE} - fi - - cd "${FZF_HOME}" || { - mucl - banner_color_err 0 "couldn't enter directory: ${FZF_HOME}" 2 - return ${FAILURE} - } - ./install --all &> /dev/null - - if (( $? != SUCCESS )); then - mucl - banner_color_err 0 "fzf installation failed." 2 - return ${FAILURE} - fi - - mucl - banner_color 0 "magenta" "*" "fzf installed." 2 -} - -function finish { - cd "${currDir}" || { - banner_color_err 0 "couldn't enter directory: ${currDir}" 2 - exit ${FAILURE} - } -} -trap finish EXIT - -##################### -# Update custom-git # -##################### - -insert_new_lines 1 - -shells=("bash" "zsh") -numShells=${#shells[@]} - -for ((i = 0 ; i < numShells ; i++)); do - shell="${shells[$i]}" - if ! $(is_command_installed "${shell}"); then - unset shells[$i] - fi -done - -if [[ ${#shells[@]} -eq 0 ]]; then - banner_color_err 0 "custom-git is only supported for bash and zsh shells. Stopping updation." 2 - print_info 0 "Visit " 0 - print_as 0 "magenta" "bold" "https://custom-git.io" 0 - print_as 0 "blue" " for more information." 2 - exit ${FAILURE} -fi - -prefix='~/.custom-git' - -CUSTOM_GIT_HOME="${HOME}"/.custom-git -FZF_HOME="${HOME}"/.fzf -CUSTOM_GIT_WEBSITE_URL="https://custom-git.io" - -if [[ ! -d "${CUSTOM_GIT_HOME}" ]]; then - banner_color_err 0 "custom-git is not installed on your system." 2 - print_info 0 "Visit " 0 - print_as 0 "magenta" "bold" "https://custom-git.io" 0 - print_as 0 "blue" " for easy installation." 2 - exit ${FAILURE} -fi - -if ! $(is_command_installed "clipboard"); then - - install_clipboard - if (( $? != SUCCESS )); then - print_info 0 "Please install clipboard-cli from " 0 - print_as 0 "magenta" "bold" "\"https://github.com/sindresorhus/clipboard-cli\"" 1 - print_info 0 "Otherwise, some custom-git commands may not work correctly." 2 - fi -fi - -if ! $(is_command_installed "fzf"); then - - install_fzf - if (( $? != SUCCESS )); then - print_info 0 "Please try again after installing fzf from " 0 - print_as 0 "magenta" "bold" "https://github.com/junegunn/fzf#installation" 2 - exit ${FAILURE} - fi -fi - -cd "${CUSTOM_GIT_HOME}" || { - banner_color_err 0 "couldn't enter directory: ${CUSTOM_GIT_HOME}" 2 - exit ${FAILURE} -} - -########## handle v0.1.0 install issues ########## -currVersion="$(get_latest_annotated_tag)" -if [[ "${currVersion}" == "" || "${currVersion}" == "v0.1.0" ]]; then - for shell in "${shells[@]}"; do - initFile="${CUSTOM_GIT_HOME}.${shell}" - [ -f "${initFile}" ] && { - remove_file "${initFile}" - remove_line ~/.${shell}rc \ - "[ -f ${prefix}.${shell} ] && source ${prefix}.${shell}" \ - "source ${prefix}.${shell}" - } - done - clone_depth=$(git rev-list --count --all) - if [[ ${clone_depth} -eq 1 ]]; then - git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*' - git fetch --unshallow &> /dev/null - fi -fi -################################################## - -git switch main &> /dev/null -git pull --quiet -git fetch --all --tags --prune --prune-tags --quiet # reference:- https://stackoverflow.com/a/49215190 -assert_success "Fetching custom-git failed. Please check your network." - -latestVersion="$(get_latest_annotated_tag)" -if [[ "${currVersion}" == "${latestVersion}" ]]; then - git checkout "${currVersion}" &> /dev/null - print_info 0 "(${currVersion}) Already up to date." 1 - exit ${SUCCESS} -fi - -print_info 0 "Updating - custom-git ${latestVersion}..." 1 -git checkout "${latestVersion}" &> /dev/null -assert_success "Switching to new version failed. Please check your network." - -git submodule update --init --recursive &> /dev/null -assert_success "Submodule update failed. Please check your network." - -newVersion="$(get_latest_annotated_tag)" -assert_equal "${newVersion}" "${latestVersion}" \ - "Couldn't update custom-git to ${latestVersion}. Unknown error." - -for shell in "${shells[@]}"; do - [ $shell = zsh ] && dest=${ZDOTDIR:-~}/.zshrc || dest=~/.bashrc - append_line "[ -f ${prefix}/init.${shell} ] && source ${prefix}/init.${shell}" \ - "$dest" "source ${prefix}/init.${shell}" -done - -mucl -print_info 1 "For more details, visit: " 0 -print_as 0 "magenta" "bold" "${CUSTOM_GIT_WEBSITE_URL}" 2 - -banner_color 0 "magenta" "*" "Update complete - custom-git ${latestVersion}" 2 - -print_info 0 "Restart your shell or reload config file." 1 -for shell in "${shells[@]}"; do - case "${shell}" in - bash) - printf " source ~/.bashrc # bash" - archi=$(uname -sm) - [[ "$archi" =~ Darwin ]] && printf " (~/.bashrc should be sourced from ~/.bash_profile)" - echo - ;; - zsh) - echo " source ${ZDOTDIR:-~}/.zshrc # zsh" - ;; - *) - printf "\n %s shell is not supported.\n" "${shell}" - ;; - esac -done From 0de374211873f0c2ac7b9738f5e562fac8cdc183 Mon Sep 17 00:00:00 2001 From: Bhavi Dhingra Date: Tue, 5 Oct 2021 04:37:00 +0530 Subject: [PATCH 2/2] ci: update .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index dfcfd56..0983ae4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +.jekyll-cache/ +.jekyll-metadata + # User-specific files *.rsuser *.suo