Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty commandline #4

Merged
merged 1 commit into from
Jul 4, 2022
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
2 changes: 1 addition & 1 deletion conf.d/fifc.fish
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fifc \
-p _fifc_preview_opt \
-o _fifc_open_opt
fifc \
-n 'test -n "$fifc_desc"; and type -q -f -- "$fifc_candidate"' \
-n 'test \( -n "$fifc_desc" -o -z "$fifc_commandline" \); and type -q -f -- "$fifc_candidate"' \
-r '^(?!\\w+\\h+)' \
-p _fifc_preview_cmd \
-o _fifc_open_cmd
Expand Down
43 changes: 24 additions & 19 deletions functions/_fifc.fish
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
function _fifc
set -l fish_version (string split -- '.' $FISH_VERSION)
set -l complist
set -l result
set -Ux _fifc_extract_regex
set -gx _fifc_complist
Expand All @@ -18,29 +17,32 @@ function _fifc

set -l query $fifc_commandline

# Get completion list
# --escape is only available on fisher 3.4+
if test $fish_version[2] -ge 4
set complist (complete -C --escape $fifc_commandline)
else
set complist (complete -C $fifc_commandline)
if test \( $fish_version[1] -eq 3 -a $fish_version[2] -ge 4 \) -o \( $fish_version[1] -gt 3 \)
set complete_opts --escape
end

# Split using '/' as it can't be used in filenames
set -gx _fifc_complist (string join -- $_fifc_complist_sep $complist)
# Don't trigger fifc on empty commandline to avoid exceeding OS argument length limit
if test -n (string trim -- $fifc_commandline)
# Split using '/' as it can't be used in filenames
set -gx _fifc_complist ( \
complete -C $complete_opts "$fifc_commandline" \
| string join -- $_fifc_complist_sep \
)

if string match --quiet --regex -- '\w+ +-+ *$' "$fifc_commandline"
set -e query
else
# Set intial query to the last token from commandline buffer
set query (string split -- ' ' $query)
set query $query[-1]
end

if string match --quiet --regex -- '\w+ +-+ *$' "$fifc_commandline"
set -e query
set source_cmd (_fifc_action source)
else
# Set intial query to the last token from commandline buffer
set query (string split -- ' ' $query)
set query $query[-1]
set source_cmd "complete -C $complete_opts | awk -F \\t '{ print \$1 }'"
end

# We use eval hack because wrapping source command
# inside a function cause some delay before fzf to show up
# set -l source_cmd (_fifc_source_cmd)
set -l source_cmd (_fifc_action source)
set -l fzf_cmd "
fzf \
-d \t \
Expand All @@ -58,11 +60,14 @@ function _fifc
--query '$query' \
$_fifc_custom_fzf_opts"

set -l cmd (string join -- " | " $source_cmd $fzf_cmd)

# Perform extraction if needed
set -l cmd (string join -- " | " $source_cmd $fzf_cmd)
# We use eval hack because wrapping source command
# inside a function cause some delay before fzf to show up
# set -l source_cmd (_fifc_source_cmd)
eval $cmd | while read -l token
set -a result (string escape -- $token)
# Perform extraction if needed
if test -n "$_fifc_extract_regex"
set result[-1] (string match --regex --groups-only -- "$_fifc_extract_regex" "$token")
end
Expand Down