diff options
Diffstat (limited to 'scripts/deploy')
| -rw-r--r-- | scripts/deploy/completions/bash.sh | 65 | ||||
| -rw-r--r-- | scripts/deploy/completions/fish.fish | 43 | ||||
| -rw-r--r-- | scripts/deploy/completions/powershell.ps1 | 42 | ||||
| -rw-r--r-- | scripts/deploy/completions/zsh.sh | 48 | ||||
| -rw-r--r-- | scripts/deploy/jv_cli.ps1 | 4 | ||||
| -rwxr-xr-x | scripts/deploy/jv_cli.sh | 8 | ||||
| -rw-r--r-- | scripts/deploy/jvn.ps1 | 13 | ||||
| -rw-r--r-- | scripts/deploy/jvn.sh | 25 | ||||
| -rwxr-xr-x | scripts/deploy/legacy_completions/bash/completion_jv.sh (renamed from scripts/deploy/completions/bash/completion_jv.sh) | 0 | ||||
| -rwxr-xr-x | scripts/deploy/legacy_completions/bash/completion_jvv.sh (renamed from scripts/deploy/completions/bash/completion_jvv.sh) | 0 | ||||
| -rw-r--r-- | scripts/deploy/legacy_completions/powershell/completion_jv.ps1 (renamed from scripts/deploy/completions/powershell/completion_jv.ps1) | 0 | ||||
| -rw-r--r-- | scripts/deploy/legacy_completions/powershell/completion_jvv.ps1 (renamed from scripts/deploy/completions/powershell/completion_jvv.ps1) | 0 | ||||
| -rw-r--r-- | scripts/deploy/legacy_zsh_support/how_to_install.md (renamed from scripts/deploy/zsh_support/how_to_install.md) | 0 | ||||
| -rwxr-xr-x | scripts/deploy/legacy_zsh_support/install.sh (renamed from scripts/deploy/zsh_support/install.sh) | 0 | ||||
| -rw-r--r-- | scripts/deploy/legacy_zsh_support/jvcs.plugin.zsh (renamed from scripts/deploy/zsh_support/jvcs.plugin.zsh) | 0 |
15 files changed, 242 insertions, 6 deletions
diff --git a/scripts/deploy/completions/bash.sh b/scripts/deploy/completions/bash.sh new file mode 100644 index 0000000..418105d --- /dev/null +++ b/scripts/deploy/completions/bash.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +_jvn_bash_completion() { + local cur prev words cword + + local line="${COMP_LINE}" + local point="${COMP_POINT}" + + if [ "${point}" -gt "${#line}" ]; then + point="${#line}" + fi + + words=($line) + cword=0 + + local i=0 + local pos=0 + for word in "${words[@]}"; do + local word_start=$pos + local word_end=$((pos + ${#word})) + + if [ "${point}" -ge "${word_start}" ] && [ "${point}" -le "${word_end}" ]; then + cword=$i + cur="${word}" + break + fi + + pos=$((pos + ${#word} + 1)) + i=$((i + 1)) + done + + if [ "${point}" -gt "${pos}" ]; then + cword=${#words[@]} + cur="" + fi + + if [ "${cword}" -gt 0 ]; then + prev="${words[$((cword-1))]}" + else + prev="" + fi + + local args=( + -f "$COMP_LINE" + -C "$COMP_POINT" + -w "$cur" + -p "$prev" + -c "${words[0]}" + -i "$cword" + -a "${words[@]}" + ) + + local suggestions + if suggestions=$(jvn_comp "${args[@]}" 2>/dev/null); then + if [ "$suggestions" = "_file_" ]; then + compopt -o default + COMPREPLY=() + else + mapfile -t COMPREPLY < <(printf '%s\n' "$suggestions") + fi + else + COMPREPLY=() + fi +} + +complete -F _jvn_bash_completion jvn diff --git a/scripts/deploy/completions/fish.fish b/scripts/deploy/completions/fish.fish new file mode 100644 index 0000000..2904495 --- /dev/null +++ b/scripts/deploy/completions/fish.fish @@ -0,0 +1,43 @@ +#!/usr/bin/env fish +function __jvn_fish_complete + set -l cmdline (commandline -opc) + set -l buffer (commandline -b) + set -l cursor (commandline -C) + + set -l current_word "" + set -l previous_word "" + set -l word_index 0 + set -l char_count 0 + + for i in (seq (count $cmdline)) + set word $cmdline[$i] + set char_count (math $char_count + (string length "$word") + 1) + + if test $cursor -le $char_count + set word_index $i + set current_word $word + if test $i -gt 1 + set previous_word $cmdline[(math $i - 1)] + end + break + end + end + + set -l args \ + -f "$buffer" \ + -C "$cursor" \ + -w "$current_word" \ + -p "$previous_word" \ + -c "$cmdline[1]" \ + -i "$word_index" \ + -a $cmdline + + set -l output (jvn_comp $args 2>/dev/null) + if test "$output" = "_file_" + __fish_complete_path "$current_word" + else + printf "%s\n" $output + end +end + +complete -c jvn -a '(__jvn_fish_complete)' diff --git a/scripts/deploy/completions/powershell.ps1 b/scripts/deploy/completions/powershell.ps1 new file mode 100644 index 0000000..0c3cddc --- /dev/null +++ b/scripts/deploy/completions/powershell.ps1 @@ -0,0 +1,42 @@ +Register-ArgumentCompleter -CommandName jvn -ScriptBlock { + param($wordToComplete, $commandAst, $cursorPosition) + + $line = $commandAst.ToString() + $commandName = if ($commandAst.CommandElements.Count -gt 0) { + $commandAst.CommandElements[0].Value + } else { "" } + + $words = @() + $currentIndex = 0 + $parser = [System.Management.Automation.PSParser] + $tokens = $parser::Tokenize($line, [ref]$null) + + foreach ($token in $tokens) { + if ($token.Type -in 'CommandArgument', 'CommandParameter') { + $words += $token.Content + } + } + + $args = @( + "-f", $line + "-C", $cursorPosition.ToString() + "-w", $wordToComplete + "-p", if ($words.Count -gt 1) { $words[-2] } else { "" } + "-c", $commandName + "-i", ($words.Count - 1).ToString() + "-a", $words + ) + + $suggestions = jvn_comp $args 2>$null + + if ($suggestions) { + $suggestions | ForEach-Object { + if ($_ -eq "_file_") { + $completionType = 'ProviderItem' + } else { + $completionType = 'ParameterValue' + } + [System.Management.Automation.CompletionResult]::new($_, $_, $completionType, $_) + } + } +} diff --git a/scripts/deploy/completions/zsh.sh b/scripts/deploy/completions/zsh.sh new file mode 100644 index 0000000..2b2a96b --- /dev/null +++ b/scripts/deploy/completions/zsh.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env zsh +_jvn_completion() { + local -a args + local suggestions + + local buffer="$BUFFER" + local cursor="$CURSOR" + local current_word="${words[$CURRENT]}" + local previous_word="" + local command_name="${words[1]}" + local word_index="$CURRENT" + + if [[ $CURRENT -gt 1 ]]; then + previous_word="${words[$((CURRENT-1))]}" + fi + + args=( + -f "$buffer" + -C "$cursor" + -w "$current_word" + -p "$previous_word" + -c "$command_name" + -i "$word_index" + -a "${words[@]}" + ) + + suggestions=$(jvn_comp "${args[@]}" 2>/dev/null) + + if [[ $? -eq 0 ]] && [[ -n "$suggestions" ]]; then + local -a completions + completions=(${(f)suggestions}) + + if [[ "${completions[1]}" == "_file_" ]]; then + shift completions + _files + elif (( $+functions[_describe] )); then + _describe 'jvn commands' completions + else + compadd -a completions + fi + fi +} + +compdef _jvn_completion jvn + +if [[ $? -ne 0 ]]; then + compctl -K _jvn_completion jvn +fi diff --git a/scripts/deploy/jv_cli.ps1 b/scripts/deploy/jv_cli.ps1 index 2761137..3de330a 100644 --- a/scripts/deploy/jv_cli.ps1 +++ b/scripts/deploy/jv_cli.ps1 @@ -47,10 +47,10 @@ Set-Alias jmv jmv ### COMPLETION ### ################## -if (Test-Path "$SCRIPT_DIR\comp\jv.ps1") { +if (Test-Path "$SCRIPT_DIR\_legacy\comp\jv.ps1") { . "$SCRIPT_DIR\comp\jv.ps1" } -if (Test-Path "$SCRIPT_DIR\comp\jvv.ps1") { +if (Test-Path "$SCRIPT_DIR\_legacy\comp\jvv.ps1") { . "$SCRIPT_DIR\comp\jvv.ps1" } diff --git a/scripts/deploy/jv_cli.sh b/scripts/deploy/jv_cli.sh index 80ff757..b5212af 100755 --- a/scripts/deploy/jv_cli.sh +++ b/scripts/deploy/jv_cli.sh @@ -58,11 +58,11 @@ alias jvu='jv update' ### COMPLETION ### ################## -if [ -f "$SCRIPT_DIR/comp/jv.sh" ]; then - source "$SCRIPT_DIR/comp/jv.sh" +if [ -f "$SCRIPT_DIR/_legacy/comp/jv.sh" ]; then + source "$SCRIPT_DIR/_legacy/comp/jv.sh" fi -if [ -f "$SCRIPT_DIR/comp/jvv.sh" ]; then - source "$SCRIPT_DIR/comp/jvv.sh" +if [ -f "$SCRIPT_DIR/_legacy/comp/jvv.sh" ]; then + source "$SCRIPT_DIR/_legacy/comp/jvv.sh" fi ################## diff --git a/scripts/deploy/jvn.ps1 b/scripts/deploy/jvn.ps1 new file mode 100644 index 0000000..64959d0 --- /dev/null +++ b/scripts/deploy/jvn.ps1 @@ -0,0 +1,13 @@ +$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Definition + +# Completion +$completionScript = Join-Path $SCRIPT_DIR "comp\jvn_pwsl.ps1" +if (Test-Path $completionScript) { + . $completionScript +} + +# Envirement +$binPath = Join-Path $SCRIPT_DIR "bin" +if (Test-Path $binPath) { + $env:PATH = "$binPath;$env:PATH" +} diff --git a/scripts/deploy/jvn.sh b/scripts/deploy/jvn.sh new file mode 100644 index 0000000..25c6ad5 --- /dev/null +++ b/scripts/deploy/jvn.sh @@ -0,0 +1,25 @@ +#!bin/bash +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" + +# Completion script +if [ -n "$BASH_VERSION" ]; then + # Bash + if [ -f "$SCRIPT_DIR/comp/jvn_bash.sh" ]; then + source "$SCRIPT_DIR/comp/jvn_bash.sh" + fi +elif [ -n "$ZSH_VERSION" ]; then + # Zsh + if [ -f "$SCRIPT_DIR/comp/jvn_zsh.sh" ]; then + source "$SCRIPT_DIR/comp/jvn_zsh.sh" + fi +elif [ -n "$FISH_VERSION" ]; then + # Fish + if [ -f "$SCRIPT_DIR/comp/jvn_fish.fish" ]; then + source "$SCRIPT_DIR/comp/jvn_fish.fish" + fi +fi + +# Envirement +if [ -d "$SCRIPT_DIR/bin" ]; then + export PATH="$SCRIPT_DIR/bin:$PATH" +fi diff --git a/scripts/deploy/completions/bash/completion_jv.sh b/scripts/deploy/legacy_completions/bash/completion_jv.sh index 364df9d..364df9d 100755 --- a/scripts/deploy/completions/bash/completion_jv.sh +++ b/scripts/deploy/legacy_completions/bash/completion_jv.sh diff --git a/scripts/deploy/completions/bash/completion_jvv.sh b/scripts/deploy/legacy_completions/bash/completion_jvv.sh index ce5668b..ce5668b 100755 --- a/scripts/deploy/completions/bash/completion_jvv.sh +++ b/scripts/deploy/legacy_completions/bash/completion_jvv.sh diff --git a/scripts/deploy/completions/powershell/completion_jv.ps1 b/scripts/deploy/legacy_completions/powershell/completion_jv.ps1 index 84ba01a..84ba01a 100644 --- a/scripts/deploy/completions/powershell/completion_jv.ps1 +++ b/scripts/deploy/legacy_completions/powershell/completion_jv.ps1 diff --git a/scripts/deploy/completions/powershell/completion_jvv.ps1 b/scripts/deploy/legacy_completions/powershell/completion_jvv.ps1 index fa773c0..fa773c0 100644 --- a/scripts/deploy/completions/powershell/completion_jvv.ps1 +++ b/scripts/deploy/legacy_completions/powershell/completion_jvv.ps1 diff --git a/scripts/deploy/zsh_support/how_to_install.md b/scripts/deploy/legacy_zsh_support/how_to_install.md index 343ea7b..343ea7b 100644 --- a/scripts/deploy/zsh_support/how_to_install.md +++ b/scripts/deploy/legacy_zsh_support/how_to_install.md diff --git a/scripts/deploy/zsh_support/install.sh b/scripts/deploy/legacy_zsh_support/install.sh index aa92952..aa92952 100755 --- a/scripts/deploy/zsh_support/install.sh +++ b/scripts/deploy/legacy_zsh_support/install.sh diff --git a/scripts/deploy/zsh_support/jvcs.plugin.zsh b/scripts/deploy/legacy_zsh_support/jvcs.plugin.zsh index ff3f213..ff3f213 100644 --- a/scripts/deploy/zsh_support/jvcs.plugin.zsh +++ b/scripts/deploy/legacy_zsh_support/jvcs.plugin.zsh |
