Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Error "test: Missing argument at index 2" for "string match *ahead*/*behind*" #220

Open
personinblack opened this issue Sep 22, 2020 · 2 comments

Comments

@personinblack
Copy link

personinblack commented Sep 22, 2020

Bug Report

Current Behavior
I see this error when I am in my dotfiles:

test: Missing argument at index 2

~/.config/fish/functions/__sf_section_git_status.fish (line 66):
        if test (string match '*ahead*' $index)
           ^
in function '__sf_section_git_status'
        called on line 1 of file ~/.config/fish/functions/__sf_section_git.fish
in command substitution
        called on line 26 of file ~/.config/fish/functions/__sf_section_git.fish
in function '__sf_section_git'
        called on line 1 of file ~/.config/fish/functions/fish_prompt.fish
in function 'fish_prompt'
in command substitution

with $index ==

## master...origin/master
 M fish/.config/fish/conf.d/fzf.fish
 M fish/.config/fish/conf.d/fzf_key_bindings.fish
 M fish/.config/fish/conf.d/z.fish
 M fish/.config/fish/fish_variables
 M fish/.config/fish/functions/__fzf_open.fish
 M fish/.config/fish/functions/__fzf_reverse_isearch.fish
 M fish/.config/fish/functions/__z.fish
 M fish/.config/fish/functions/__z_add.fish
 M fish/.config/fish/functions/__z_clean.fish
 M fish/.config/fish/functions/__z_complete.fish
 M fish/.config/fish/functions/fish_prompt.fish
 M fish/.config/fish/functions/fish_right_prompt.fish
 M fish/.config/fish/functions/fisher.fish
 D fish/.config/fish/functions/git_ahead.fish
 D fish/.config/fish/functions/git_branch_name.fish
 D fish/.config/fish/functions/git_is_detached_head.fish
 D fish/.config/fish/functions/git_is_dirty.fish
 D fish/.config/fish/functions/git_is_empty.fish
 D fish/.config/fish/functions/git_is_repo.fish
 D fish/.config/fish/functions/git_is_staged.fish
 D fish/.config/fish/functions/git_is_stashed.fish
 D fish/.config/fish/functions/git_is_tag.fish
 D fish/.config/fish/functions/git_is_touched.fish
 D fish/.config/fish/functions/git_repository_root.fish
 D fish/.config/fish/functions/git_untracked_files.fish
 D fish/.config/fish/functions/host_info.fish
 D fish/.config/fish/functions/humanize_duration.fish
 D fish/.config/fish/functions/last_job_id.fish
 D fish/.config/fish/functions/pwd_info.fish
 D fish/.config/fish/functions/pwd_is_home.fish
?? fish/.config/fish/functions/__sf_lib_section.fish
?? fish/.config/fish/functions/__sf_section_aws.fish
?? fish/.config/fish/functions/__sf_section_battery.fish
?? fish/.config/fish/functions/__sf_section_char.fish
?? fish/.config/fish/functions/__sf_section_conda.fish
?? fish/.config/fish/functions/__sf_section_dir.fish
?? fish/.config/fish/functions/__sf_section_docker.fish
?? fish/.config/fish/functions/__sf_section_dotnet.fish
?? fish/.config/fish/functions/__sf_section_elixir.fish
?? fish/.config/fish/functions/__sf_section_exec_time.fish
?? fish/.config/fish/functions/__sf_section_exit_code.fish
?? fish/.config/fish/functions/__sf_section_git.fish
?? fish/.config/fish/functions/__sf_section_git_branch.fish
?? fish/.config/fish/functions/__sf_section_git_status.fish
?? fish/.config/fish/functions/__sf_section_golang.fish
?? fish/.config/fish/functions/__sf_section_haskell.fish
?? fish/.config/fish/functions/__sf_section_host.fish
?? fish/.config/fish/functions/__sf_section_jobs.fish
?? fish/.config/fish/functions/__sf_section_julia.fish
?? fish/.config/fish/functions/__sf_section_kubecontext.fish
?? fish/.config/fish/functions/__sf_section_line_sep.fish
?? fish/.config/fish/functions/__sf_section_node.fish
?? fish/.config/fish/functions/__sf_section_package.fish
?? fish/.config/fish/functions/__sf_section_php.fish
?? fish/.config/fish/functions/__sf_section_pyenv.fish
?? fish/.config/fish/functions/__sf_section_ruby.fish
?? fish/.config/fish/functions/__sf_section_rust.fish
?? fish/.config/fish/functions/__sf_section_time.fish
?? fish/.config/fish/functions/__sf_section_user.fish
?? fish/.config/fish/functions/__sf_section_venv.fish
?? fish/.config/fish/functions/__sf_section_vi_mode.fish
?? fish/.config/fish/functions/__sf_util_git_branch.fish
?? fish/.config/fish/functions/__sf_util_human_time.fish
?? fish/.config/fish/functions/__sf_util_set_default.fish
?? fish/.config/fish/functions/__sf_util_truncate_dir.fish
?? fish/.config/fish/functions/daf.fish
?? fish/.config/fish/functions/fish_mode_prompt.fish

Relevant Fish Configuration
https://github.com/personinblack/dotfiles/blob/master/fish/.config/fish/config.fish

Environment

  • Spacefish version: 2.7.0
  • Fish version: 3.1.2
  • Fish plugin manager: fisher
  • Terminal emulator: suckless terminal
  • Operating system: Arch Linux

Possible Solution
Putting $indexs inside quotes fixes it. Like this: test (string match '*ahead*' "$index")

Additional context/Screenshots
Don't know if this is the right way to fix or if I get this error because of my configuration. I can create a PR if it's okay.

@cgsimmons
Copy link

cgsimmons commented Oct 5, 2020

The quotes just essential disable the match I think (which you would see that the ahead and before symbols are no longer present in the prompt). The issue is that index is empty for some reason which breaks the call to match (now missing an argument).

@cgsimmons
Copy link

Ok, after reading the docs, it seems that "If [variable] is not defined, then it will expand to zero arguments, unless quoted"
https://fishshell.com/docs/current/cmds/test.html?highlight=test#examples
So I was wrong, the condition still functions as long as index is defined. I had this happen on one of my repos as well. The quotes did fix it, but I have no idea why index would be undefined. 🤷

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants