Skip to content

Commit

Permalink
ref+fix(vim-commentary): fix inconsistencies in install files
Browse files Browse the repository at this point in the history
  • Loading branch information
coolaj86 committed Nov 2, 2023
1 parent bd47c3b commit bf5482c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
37 changes: 21 additions & 16 deletions vim-commentary/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ IF ($null -eq $Env:WEBI_HOST -or "" -eq $Env:WEBI_HOST) {
# Install vim-commentary #
##########################

# Every package should define these variables
$pkg_cmd_name = "vim-commentary"
$pkg_src = "$HOME\Downloads\webi\$Env:WEBI_PKG_PATHNAME"
$pkg_dst = "$HOME\.vim\pack\plugins\start\$Env:PKG_NAME"
# ~/.vim/plugins/<vim-name>.vim
$my_vim_confname = "commentary.vim"

# ~/.vim/pack/plugins/start/<vim-plugin>/
$my_vim_plugin = "vim-commentary"

$my_vim_filename = "commentary.vim"
# Non-executable packages should define these variables
$pkg_cmd_name = "${my_vim_plugin}"
$pkg_no_exec = $true
$pkg_src = "$HOME\Downloads\webi\$Env:WEBI_PKG_PATHNAME"
$pkg_dst = "$HOME\.vim\pack\plugins\start\$my_vim_plugin"

function fn_vim_init {
if (-Not (Test-Path "$HOME\.vimrc")) {
Expand All @@ -26,10 +31,10 @@ function fn_vim_init {
}

function fn_git_shallow_clone {
# IF (Test-Path -Path "$pkg_src") {
# Write-Host "Found $pkg_src"
# Return
# }
IF (Test-Path -Path "$pkg_src") {
Write-Host "Found $pkg_src"
Return
}

Write-Output "Checking for Git..."
IF (-Not (Get-Command -Name "git" -ErrorAction Silent)) {
Expand Down Expand Up @@ -62,18 +67,18 @@ function fn_install {
}

function fn_vim_config_download {
$my_vim_filepath = "$HOME\.vim\plugins\$my_vim_filename"
IF (Test-Path -Path "$my_vim_filepath") {
Write-Host "Found $my_vim_filepath"
$my_vim_confpath = "$HOME\.vim\plugins\$my_vim_confname"
IF (Test-Path -Path "$my_vim_confpath") {
Write-Host "Found $my_vim_confpath"
Return
}

& curl.exe -sS -o "$my_vim_filepath" `
"$Env:WEBI_HOST/packages/${Env:PKG_NAME}/${my_vim_filename}"
& curl.exe -sS -o "$my_vim_confpath" `
"$Env:WEBI_HOST/packages/${Env:PKG_NAME}/${my_vim_confname}"
}

function fn_vim_config_update {
$my_vim_filepath = "$HOME\.vim\plugin\$my_vim_filename"
$my_vim_confpath = "$HOME\.vim\plugin\$my_vim_confname"


Write-Host ''
Expand All @@ -82,7 +87,7 @@ function fn_vim_config_update {
Write-Host ''
Write-Host "Add the following to ~/.vimrc:" `
-ForegroundColor magenta -BackgroundColor white
Write-Host " source $my_vim_filepath" `
Write-Host " source $my_vim_confpath" `
-ForegroundColor magenta -BackgroundColor white
Write-Host ''

Expand Down
41 changes: 21 additions & 20 deletions vim-commentary/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,45 @@ fn_vim_init() { (
); }

__install_vim_plugin() {
# ~/.vim/plugins/<vim-name>.vim
my_vim_confname="commentary.vim"

# ~/.vim/pack/plugins/start/<vim-plugin>/
my_vim_plugin="vim-commentary"

# as opposed to PKG_NAME-<version> / WEBI_PKG_PATHNAME:
# ~/Downloads/webi/<PKG_NAME>-<version>/

# Non-executable packages should define these variables
pkg_cmd_name="vim-commentary"
pkg_cmd_name="${my_vim_plugin}"
pkg_no_exec=true
pkg_dst="${HOME}/.vim/pack/plugins/start/vim-commentary"

my_name="commentary"
my_pkg_name="vim-commentary"
my_note="${my_pkg_name}: installed via webinstall.dev/${my_pkg_name}"
pkg_dst="${HOME}/.vim/pack/plugins/start/${my_vim_plugin}"

pkg_install() { (
fn_vim_init

rm -rf ~/.vim/pack/plugins/start/"${my_pkg_name}"/
mv ./vim-commentary-*/ ~/.vim/pack/plugins/start/"${my_pkg_name}"
); }

pkg_link() { (
return 0
rm -rf ~/.vim/pack/plugins/start/"${my_vim_plugin}"/
mv ./"${WEBI_PKG_PATHNAME}"/ ~/.vim/pack/plugins/start/"${my_vim_plugin}"
); }

pkg_post_install() { (
mkdir -p ~/.vim/plugins
if [ -f ~/.vim/plugins/"${my_name}.vim" ]; then
echo "Found ~/.vim/plugins/${my_name}.vim"
if [ -f ~/.vim/plugins/"${my_vim_confname}" ]; then
echo "Found ~/.vim/plugins/${my_vim_confname}"
else
webi_download \
"${WEBI_HOST}/packages/${my_pkg_name}/${my_name}.vim" \
~/.vim/plugins/"${my_name}.vim" \
"${my_name}.vim"
"${WEBI_HOST}/packages/${PKG_NAME}/${my_vim_confname}" \
~/.vim/plugins/"${my_vim_confname}" \
"${my_vim_confname}"
fi

if ! grep "source.*plugins.${my_name}.vim" -r ~/.vimrc > /dev/null 2> /dev/null; then
if ! grep "source.*plugins.${my_vim_confname}" -r ~/.vimrc > /dev/null 2> /dev/null; then
my_note="${my_vim_plugin}: installed via webinstall.dev/${PKG_NAME}"
set +e
printf '\n" %s\n' "${my_note}" >> ~/.vimrc
printf 'source ~/.vim/plugins/%s.vim\n' "${my_name}" >> ~/.vimrc
printf 'source ~/.vim/plugins/%s\n' "${my_vim_confname}" >> ~/.vimrc
set -e
echo "Updated ~/.vimrc to 'source ~/.vim/plugins/${my_name}.vim'"
echo "Updated ~/.vimrc to 'source ~/.vim/plugins/${my_vim_confname}'"
fi

echo ""
Expand Down

0 comments on commit bf5482c

Please sign in to comment.