Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Runfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ action :schema do
end
end

help 'Run preconfigured shfmt on any script'
usage 'shfmt SCRIPT'
action :shfmt do |args|
system "shfmt -d -i 2 -ci #{args['SCRIPT']}"
say $?.success? ? 'g`PASS`' : 'r`FAIL`'
end
6 changes: 3 additions & 3 deletions lib/completely/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class << self
def from_io(program:, io: nil)
io ||= $stdin

raise InstallError, "io must respond to #read" unless io.respond_to?(:read)
raise InstallError, "io is closed" if io.respond_to?(:closed?) && io.closed?
raise InstallError, 'io must respond to #read' unless io.respond_to?(:read)
raise InstallError, 'io is closed' if io.respond_to?(:closed?) && io.closed?

from_string program:, string: io.read
end
Expand All @@ -23,7 +23,7 @@ def from_string(program:, string:)
end

def create_tempfile
tempfile = Tempfile.new ["completely-", '.bash']
tempfile = Tempfile.new ['completely-', '.bash']
tempfiles.push tempfile
tempfile
end
Expand Down
28 changes: 25 additions & 3 deletions lib/completely/templates/template.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,46 @@
local cur=${COMP_WORDS[COMP_CWORD]}
local result=()

# words the user already typed (excluding the command itself)
local used=()
if ((COMP_CWORD > 1)); then
used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
fi

if [[ "${cur:0:1}" == "-" ]]; then
# Completing an option: offer everything (including options)
echo "$words"

else
# Completing a non-option: offer only non-options,
# and don't re-offer ones already used earlier in the line.
for word in $words; do
[[ "${word:0:1}" != "-" ]] && result+=("$word")
[[ "${word:0:1}" == "-" ]] && continue

local seen=0
for u in "${used[@]}"; do
if [[ "$u" == "$word" ]]; then
seen=1
break
fi
done
((!seen)) && result+=("$word")
done

echo "${result[*]}"

fi
}

<%= function_name %>() {
local cur=${COMP_WORDS[COMP_CWORD]}
local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")
local compwords=()
if ((COMP_CWORD > 0)); then
compwords=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
fi
local compline="${compwords[*]}"

COMPREPLY=()

% if ENV['COMPLETELY_DEBUG']
if [[ -n "$COMPLETELY_DEBUG" ]]; then
echo "compline: '$compline'" > 'completely-debug.txt'
Expand Down
28 changes: 25 additions & 3 deletions spec/approvals/cli/generated-script
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,46 @@ _mygit_completions_filter() {
local cur=${COMP_WORDS[COMP_CWORD]}
local result=()

# words the user already typed (excluding the command itself)
local used=()
if ((COMP_CWORD > 1)); then
used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
fi

if [[ "${cur:0:1}" == "-" ]]; then
# Completing an option: offer everything (including options)
echo "$words"

else
# Completing a non-option: offer only non-options,
# and don't re-offer ones already used earlier in the line.
for word in $words; do
[[ "${word:0:1}" != "-" ]] && result+=("$word")
[[ "${word:0:1}" == "-" ]] && continue

local seen=0
for u in "${used[@]}"; do
if [[ "$u" == "$word" ]]; then
seen=1
break
fi
done
((!seen)) && result+=("$word")
done

echo "${result[*]}"

fi
}

_mygit_completions() {
local cur=${COMP_WORDS[COMP_CWORD]}
local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")
local compwords=()
if ((COMP_CWORD > 0)); then
compwords=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
fi
local compline="${compwords[*]}"

COMPREPLY=()

case "$compline" in
'status'*'--branch')
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "$(git branch --format='%(refname:short)' 2>/dev/null)")" -- "$cur")
Expand Down
28 changes: 25 additions & 3 deletions spec/approvals/cli/generated-script-alt
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,46 @@ _mycomps_filter() {
local cur=${COMP_WORDS[COMP_CWORD]}
local result=()

# words the user already typed (excluding the command itself)
local used=()
if ((COMP_CWORD > 1)); then
used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
fi

if [[ "${cur:0:1}" == "-" ]]; then
# Completing an option: offer everything (including options)
echo "$words"

else
# Completing a non-option: offer only non-options,
# and don't re-offer ones already used earlier in the line.
for word in $words; do
[[ "${word:0:1}" != "-" ]] && result+=("$word")
[[ "${word:0:1}" == "-" ]] && continue

local seen=0
for u in "${used[@]}"; do
if [[ "$u" == "$word" ]]; then
seen=1
break
fi
done
((!seen)) && result+=("$word")
done

echo "${result[*]}"

fi
}

_mycomps() {
local cur=${COMP_WORDS[COMP_CWORD]}
local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")
local compwords=()
if ((COMP_CWORD > 0)); then
compwords=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
fi
local compline="${compwords[*]}"

COMPREPLY=()

case "$compline" in
'status'*'--branch')
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mycomps_filter "$(git branch --format='%(refname:short)' 2>/dev/null)")" -- "$cur")
Expand Down
28 changes: 25 additions & 3 deletions spec/approvals/cli/generated-wrapped-script
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,46 @@ give_comps() {
echo $' local cur=${COMP_WORDS[COMP_CWORD]}'
echo $' local result=()'
echo $''
echo $' # words the user already typed (excluding the command itself)'
echo $' local used=()'
echo $' if ((COMP_CWORD > 1)); then'
echo $' used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")'
echo $' fi'
echo $''
echo $' if [[ "${cur:0:1}" == "-" ]]; then'
echo $' # Completing an option: offer everything (including options)'
echo $' echo "$words"'
echo $''
echo $' else'
echo $' # Completing a non-option: offer only non-options,'
echo $' # and don\'t re-offer ones already used earlier in the line.'
echo $' for word in $words; do'
echo $' [[ "${word:0:1}" != "-" ]] && result+=("$word")'
echo $' [[ "${word:0:1}" == "-" ]] && continue'
echo $''
echo $' local seen=0'
echo $' for u in "${used[@]}"; do'
echo $' if [[ "$u" == "$word" ]]; then'
echo $' seen=1'
echo $' break'
echo $' fi'
echo $' done'
echo $' ((!seen)) && result+=("$word")'
echo $' done'
echo $''
echo $' echo "${result[*]}"'
echo $''
echo $' fi'
echo $'}'
echo $''
echo $'_mygit_completions() {'
echo $' local cur=${COMP_WORDS[COMP_CWORD]}'
echo $' local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")'
echo $' local compwords=()'
echo $' if ((COMP_CWORD > 0)); then'
echo $' compwords=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")'
echo $' fi'
echo $' local compline="${compwords[*]}"'
echo $''
echo $' COMPREPLY=()'
echo $''
echo $' case "$compline" in'
echo $' \'status\'*\'--branch\')'
echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "$(git branch --format=\'%(refname:short)\' 2>/dev/null)")" -- "$cur")'
Expand Down
28 changes: 25 additions & 3 deletions spec/approvals/cli/test/completely-tester-1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,46 @@ _mygit_completions_filter() {
local cur=${COMP_WORDS[COMP_CWORD]}
local result=()

# words the user already typed (excluding the command itself)
local used=()
if ((COMP_CWORD > 1)); then
used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
fi

if [[ "${cur:0:1}" == "-" ]]; then
# Completing an option: offer everything (including options)
echo "$words"

else
# Completing a non-option: offer only non-options,
# and don't re-offer ones already used earlier in the line.
for word in $words; do
[[ "${word:0:1}" != "-" ]] && result+=("$word")
[[ "${word:0:1}" == "-" ]] && continue

local seen=0
for u in "${used[@]}"; do
if [[ "$u" == "$word" ]]; then
seen=1
break
fi
done
((!seen)) && result+=("$word")
done

echo "${result[*]}"

fi
}

_mygit_completions() {
local cur=${COMP_WORDS[COMP_CWORD]}
local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")
local compwords=()
if ((COMP_CWORD > 0)); then
compwords=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
fi
local compline="${compwords[*]}"

COMPREPLY=()

case "$compline" in
'status'*'--branch')
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "$(git branch --format='%(refname:short)' 2>/dev/null)")" -- "$cur")
Expand Down
28 changes: 25 additions & 3 deletions spec/approvals/cli/test/completely-tester-2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,46 @@ _mygit_completions_filter() {
local cur=${COMP_WORDS[COMP_CWORD]}
local result=()

# words the user already typed (excluding the command itself)
local used=()
if ((COMP_CWORD > 1)); then
used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
fi

if [[ "${cur:0:1}" == "-" ]]; then
# Completing an option: offer everything (including options)
echo "$words"

else
# Completing a non-option: offer only non-options,
# and don't re-offer ones already used earlier in the line.
for word in $words; do
[[ "${word:0:1}" != "-" ]] && result+=("$word")
[[ "${word:0:1}" == "-" ]] && continue

local seen=0
for u in "${used[@]}"; do
if [[ "$u" == "$word" ]]; then
seen=1
break
fi
done
((!seen)) && result+=("$word")
done

echo "${result[*]}"

fi
}

_mygit_completions() {
local cur=${COMP_WORDS[COMP_CWORD]}
local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")
local compwords=()
if ((COMP_CWORD > 0)); then
compwords=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
fi
local compline="${compwords[*]}"

COMPREPLY=()

case "$compline" in
'status'*'--branch')
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "$(git branch --format='%(refname:short)' 2>/dev/null)")" -- "$cur")
Expand Down
28 changes: 25 additions & 3 deletions spec/approvals/cli/test/completely-tester.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,46 @@ _mygit_completions_filter() {
local cur=${COMP_WORDS[COMP_CWORD]}
local result=()

# words the user already typed (excluding the command itself)
local used=()
if ((COMP_CWORD > 1)); then
used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
fi

if [[ "${cur:0:1}" == "-" ]]; then
# Completing an option: offer everything (including options)
echo "$words"

else
# Completing a non-option: offer only non-options,
# and don't re-offer ones already used earlier in the line.
for word in $words; do
[[ "${word:0:1}" != "-" ]] && result+=("$word")
[[ "${word:0:1}" == "-" ]] && continue

local seen=0
for u in "${used[@]}"; do
if [[ "$u" == "$word" ]]; then
seen=1
break
fi
done
((!seen)) && result+=("$word")
done

echo "${result[*]}"

fi
}

_mygit_completions() {
local cur=${COMP_WORDS[COMP_CWORD]}
local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")
local compwords=()
if ((COMP_CWORD > 0)); then
compwords=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")
fi
local compline="${compwords[*]}"

COMPREPLY=()

case "$compline" in
'status'*'--branch')
while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_mygit_completions_filter "$(git branch --format='%(refname:short)' 2>/dev/null)")" -- "$cur")
Expand Down
Loading