Skip to content

Commit

Permalink
chore(scripts): separate clone_repo from the main function
Browse files Browse the repository at this point in the history
Signed-off-by: Jint-lzxy <[email protected]>
  • Loading branch information
Jint-lzxy committed Apr 7, 2024
1 parent 3b79009 commit 41304dc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 62 deletions.
55 changes: 23 additions & 32 deletions scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ $REQUIRED_NVIM_VERSION_LEGACY = [version]'0.8.0'
$USE_SSH = $True

# package mgr vars
$choco_package_matrix = @{ "gcc" = "mingw"; "git" = "git"; "nvim" = "neovim"; "make" = "make"; "sudo" = "psutils"; "node" = "nodejs"; "pip" = "python3"; "fzf" = "fzf"; "rg" = "ripgrep"; "go" = "go"; "curl" = "curl"; "wget" = "wget"; "tree-sitter" = "tree-sitter"; "ruby" = "ruby"; "sqlite3" = "sqlite"; "rustc" = "rust-ms" }
$scoop_package_matrix = @{ "gcc" = "mingw"; "git" = "git"; "nvim" = "neovim"; "make" = "make"; "sudo" = "psutils"; "node" = "nodejs"; "pip" = "python"; "fzf" = "fzf"; "rg" = "ripgrep"; "go" = "go"; "curl" = "curl"; "wget" = "wget"; "tree-sitter" = "tree-sitter"; "ruby" = "ruby"; "sqlite3" = "sqlite"; "rustc" = "rust" }
$choco_package_matrix = @{ "gcc" = "mingw"; "git" = "git"; "nvim" = "neovim"; "make" = "make"; "sudo" = "psutils"; "node" = "nodejs"; "pip" = "python3"; "fzf" = "fzf"; "rg" = "ripgrep"; "go" = "go"; "curl" = "curl"; "wget" = "wget"; "tree-sitter" = "tree-sitter"; "ruby" = "ruby"; "rustc" = "rust-ms" }
$scoop_package_matrix = @{ "gcc" = "mingw"; "git" = "git"; "nvim" = "neovim"; "make" = "make"; "sudo" = "psutils"; "node" = "nodejs"; "pip" = "python"; "fzf" = "fzf"; "rg" = "ripgrep"; "go" = "go"; "curl" = "curl"; "wget" = "wget"; "tree-sitter" = "tree-sitter"; "ruby" = "ruby"; "rustc" = "rust" }
$installer_pkg_matrix = @{ "NodeJS" = "npm"; "Python" = "pip"; "Ruby" = "gem" }

# env vars
$env:XDG_CONFIG_HOME ??= $env:LOCALAPPDATA
$env:CCPACK_MGR ??= 'unknown'
$env:CCLONE_BRANCH ??= 'master'
$env:CCLONE_BRANCH_LEGACY ??= '0.8'
$env:CCLONE_ATTR ??= 'undef'
$env:CCDEST_DIR ??= "$env:XDG_CONFIG_HOME\nvim"
$env:CCBACKUP_DIR = "$env:CCDEST_DIR" + "_backup-" + (Get-Date).ToUniversalTime().ToString("yyyyMMddTHHmmss")
Expand Down Expand Up @@ -121,7 +122,7 @@ function check_clone_pref {
if ($USR_CHOICE -eq 0) {
$env:CCLONE_ATTR = '--depth=1'
} else {
$env:CCLONE_ATTR = ''
$env:CCLONE_ATTR = '--progress'
}
}

Expand Down Expand Up @@ -266,7 +267,6 @@ function fetch_deps {
check_and_fetch_exec -PkgName "curl"
check_and_fetch_exec -PkgName "wget"
check_and_fetch_exec -PkgName "rustc"
check_and_fetch_exec -PkgName "sqlite3"
check_and_fetch_exec -PkgName "tree-sitter"

# Reload PATH for future use
Expand All @@ -283,6 +283,23 @@ function check_nvim_version ([Parameter(Mandatory = $True)][ValidateNotNullOrEmp
return ($nvim_version -ge $RequiredVersionMin)
}

function clone_repo ([Parameter(Mandatory = $True)][ValidateNotNullOrEmpty()] [string]$WithURL) {
if ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION)) {
safe_execute -WithCmd { git clone --progress -b "$env:CCLONE_BRANCH" "$env:CCLONE_ATTR" $WithURL "$env:CCDEST_DIR" }
} elseif ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION_LEGACY)) {
warn -Msg "You have outdated Nvim installed (< $REQUIRED_NVIM_VERSION)."
info -Msg "Automatically redirecting you to the latest compatible version..."
safe_execute -WithCmd { git clone --progress -b "$env:CCLONE_BRANCH_LEGACY" "$env:CCLONE_ATTR" $WithURL "$env:CCDEST_DIR" }
} else {
warn -Msg "You have outdated Nvim installed (< $REQUIRED_NVIM_VERSION_LEGACY)."
_abort -Msg "This Neovim distribution is no longer supported." -Type "NotImplemented" -Info_msg @"
You have a legacy Neovim distribution installed.
Please make sure you have nvim v$REQUIRED_NVIM_VERSION_LEGACY installed at the very least.
"@
}
}

function ring_bell {
[System.Console]::beep()
}
Expand Down Expand Up @@ -354,35 +371,9 @@ You must install Git before installing this Nvim config. See:
info -Msg "Fetching in progress..."

if ($USE_SSH) {
if ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION)) {
safe_execute -WithCmd { git clone --progress -b "$env:CCLONE_BRANCH" "$env:CCLONE_ATTR" '[email protected]:Jint-lzxy/nvimconfig.git' "$env:CCDEST_DIR" }
} elseif ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION_LEGACY)) {
warn -Msg "You have outdated Nvim installed (< $REQUIRED_NVIM_VERSION)."
info -Msg "Automatically redirecting you to the latest compatible version..."
safe_execute -WithCmd { git clone --progress -b 0.8 "$env:CCLONE_ATTR" '[email protected]:Jint-lzxy/nvimconfig.git' "$env:CCDEST_DIR" }
} else {
warn -Msg "You have outdated Nvim installed (< $REQUIRED_NVIM_VERSION_LEGACY)."
_abort -Msg "This Neovim distribution is no longer supported." -Type "NotImplemented" -Info_msg @"
You have a legacy Neovim distribution installed.
Please make sure you have nvim v$REQUIRED_NVIM_VERSION_LEGACY installed at the very least.
"@
}
clone_repo -WithURL '[email protected]:ayamir/nvimdots.git'
} else {
if ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION)) {
safe_execute -WithCmd { git clone --progress -b "$env:CCLONE_BRANCH" "$env:CCLONE_ATTR" 'https://github.com/Jint-lzxy/nvimconfig.git' "$env:CCDEST_DIR" }
} elseif ((check_nvim_version -RequiredVersionMin $REQUIRED_NVIM_VERSION_LEGACY)) {
warn -Msg "You have outdated Nvim installed (< $REQUIRED_NVIM_VERSION)."
info -Msg "Automatically redirecting you to the latest compatible version..."
safe_execute -WithCmd { git clone --progress -b 0.8 "$env:CCLONE_ATTR" 'https://github.com/Jint-lzxy/nvimconfig.git' "$env:CCDEST_DIR" }
} else {
warn -Msg "You have outdated Nvim installed (< $REQUIRED_NVIM_VERSION_LEGACY)."
_abort -Msg "This Neovim distribution is no longer supported." -Type "NotImplemented" -Info_msg @"
You have a legacy Neovim distribution installed.
Please make sure you have nvim v$REQUIRED_NVIM_VERSION_LEGACY installed at the very least.
"@
}
clone_repo -WithURL 'https://github.com/Jint-lzxy/nvimconfig.git'
}

safe_execute -WithCmd { Set-Location -Path "$env:CCDEST_DIR" }
Expand Down
50 changes: 20 additions & 30 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@ check_nvim_version() {
fi
}

clone_repo() {
if check_nvim_version "${REQUIRED_NVIM_VERSION}"; then
execute "git" "clone" "-b" "main" "${CLONE_ATTR[@]}" "$1" "${DEST_DIR}"
elif check_nvim_version "${REQUIRED_NVIM_VERSION_LEGACY}"; then
warn "You have outdated Nvim installed (< ${REQUIRED_NVIM_VERSION})."
info "Automatically redirecting you to the latest compatible version..."
execute "git" "clone" "-b" "0.8" "${CLONE_ATTR[@]}" "$1" "${DEST_DIR}"
else
warn "You have outdated Nvim installed (< ${REQUIRED_NVIM_VERSION_LEGACY})."
abort "$(
cat <<EOABORT
You have a legacy Neovim distribution installed.
Please make sure you have nvim v${REQUIRED_NVIM_VERSION_LEGACY} installed at the very least.
EOABORT
)"
fi
}

# Check if both `INTERACTIVE` and `NONINTERACTIVE` are set
# Always use single-quoted strings with `exp` expressions
# shellcheck disable=SC2016
Expand Down Expand Up @@ -252,37 +270,9 @@ fi

info "Fetching in progress..."
if [[ "${USE_SSH}" -eq "1" ]]; then
if check_nvim_version "${REQUIRED_NVIM_VERSION}"; then
execute "git" "clone" "-b" "master" "${CLONE_ATTR[@]}" "[email protected]:Jint-lzxy/nvimconfig.git" "${DEST_DIR}"
elif check_nvim_version "${REQUIRED_NVIM_VERSION_LEGACY}"; then
warn "You have outdated Nvim installed (< ${REQUIRED_NVIM_VERSION})."
info "Automatically redirecting you to the latest compatible version..."
execute "git" "clone" "-b" "0.8" "${CLONE_ATTR[@]}" "[email protected]:Jint-lzxy/nvimconfig.git" "${DEST_DIR}"
else
warn "You have outdated Nvim installed (< ${REQUIRED_NVIM_VERSION_LEGACY})."
abort "$(
cat <<EOABORT
You have a legacy Neovim distribution installed.
Please make sure you have nvim v${REQUIRED_NVIM_VERSION_LEGACY} installed at the very least.
EOABORT
)"
fi
clone_repo "[email protected]:Jint-lzxy/nvimconfig.git"
else
if check_nvim_version "${REQUIRED_NVIM_VERSION}"; then
execute "git" "clone" "-b" "master" "${CLONE_ATTR[@]}" "https://github.com/Jint-lzxy/nvimconfig.git" "${DEST_DIR}"
elif check_nvim_version "${REQUIRED_NVIM_VERSION_LEGACY}"; then
warn "You have outdated Nvim installed (< ${REQUIRED_NVIM_VERSION})."
info "Automatically redirecting you to the latest compatible version..."
execute "git" "clone" "-b" "0.8" "${CLONE_ATTR[@]}" "https://github.com/Jint-lzxy/nvimconfig.git" "${DEST_DIR}"
else
warn "You have outdated Nvim installed (< ${REQUIRED_NVIM_VERSION_LEGACY})."
abort "$(
cat <<EOABORT
You have a legacy Neovim distribution installed.
Please make sure you have nvim v${REQUIRED_NVIM_VERSION_LEGACY} installed at the very least.
EOABORT
)"
fi
clone_repo "https://github.com/Jint-lzxy/nvimconfig.git"
fi

cd "${DEST_DIR}" || return
Expand Down

0 comments on commit 41304dc

Please sign in to comment.