jeff-hykin / better-shell-syntax

💾 📦 ♻️ An improvement to the shell syntax for VS Code
MIT License
50 stars 4 forks source link

complex combination of commands breaks syntax highlighting #77

Closed Stanzilla closed 3 months ago

Stanzilla commented 4 months ago

image

Code:

# Use fd (https://github.com/sharkdp/fd) instead of the default find
# command for listing path candidates.
# - The first argument to the function ($1) is the base path to start traversal
# - See the source code (completion.{bash,zsh}) for the details.
_fzf_compgen_path() {
  fd --hidden --follow --exclude ".git" . "$1"
}

# Use fd to generate the list for directory completion
_fzf_compgen_dir() {
  fd --type d --hidden --follow --exclude ".git" . "$1"
}

# export NVM_DIR="$HOME/.config/nvm"
# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
# [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# Use fd and fzf to get the args to a command.
# Works only with zsh
# Examples:
# f mv # To move files. You can write the destination after selecting the files.
# f 'echo Selected:'
# f 'echo Selected music:' --extension mp3
# fm rm # To rm files in current directory
f() {
  sels=( "${(@f)$(fd "${fd_default[@]}" "${@:2}"| fzf)}" )
  test -n "$sels" && print -z -- "$1 ${sels[@]:q:q}"
}

# Like f, but not recursive.
fm() f "$@" --max-depth 1

# Deps
alias fz="fzf-noempty --bind 'tab:toggle,shift-tab:toggle+beginning-of-line+kill-line,ctrl-j:toggle+beginning-of-line+kill-line,ctrl-t:top' --color=light -1 -m"
fzf-noempty () {
  local in="$(</dev/stdin)"
  test -z "$in" && (
    exit 130
  ) || {
    ec "$in" | fzf "$@"
  }
}

ec () {
  if [[ -n $ZSH_VERSION ]]
  then
    print -r -- "$@"
  else
    echo -E -- "$@"
  fi
}
jeff-hykin commented 4 months ago

Thanks for reporting.

Notes to future me: looks like its the function definition pattern never ending. Should add a lookahead for ; to whereever its looking for }

Stanzilla commented 4 months ago

Thanks for reporting.

Notes to future me: looks like its the function definition pattern never ending. Should add a lookahead for ; to whereever its looking for }

Can confirm that writing it like this fixes it:

fm() {
    f "$@" --max-depth 1
}