From c1f90633c7ed57f25d229224c8e8cd1025d56326 Mon Sep 17 00:00:00 2001 From: kkashilk Date: Wed, 29 Oct 2025 14:35:07 -0700 Subject: [PATCH 1/4] feat(shell): Parameterize binary names in shell integration scripts - Add {{CLI_BINARY_NAME}} and {{PTY_BINARY_NAME}} placeholders to all shell scripts - Update pre.sh, pre.fish, pre.nu to use placeholders - Update post.bash, post.fish, post.zsh, post.nu to use placeholders - Modify get_fig_integration_source() to return String and perform substitution - Replace hardcoded 'q' and 'qterm' with constants from fig_util::consts - Remove unnecessary .into() call in init.rs This enables easy rebranding by changing constants in one place. --- crates/fig_integrations/src/shell/mod.rs | 15 ++++++++++----- .../fig_integrations/src/shell/scripts/post.bash | 8 ++++---- .../fig_integrations/src/shell/scripts/post.fish | 8 ++++---- crates/fig_integrations/src/shell/scripts/post.nu | 6 +++--- .../fig_integrations/src/shell/scripts/post.zsh | 8 ++++---- .../fig_integrations/src/shell/scripts/pre.fish | 12 ++++++------ crates/fig_integrations/src/shell/scripts/pre.nu | 4 ++-- crates/fig_integrations/src/shell/scripts/pre.sh | 10 +++++----- crates/q_cli/src/cli/init.rs | 2 +- 9 files changed, 39 insertions(+), 34 deletions(-) diff --git a/crates/fig_integrations/src/shell/mod.rs b/crates/fig_integrations/src/shell/mod.rs index ef76ebe2d..a51510cc0 100644 --- a/crates/fig_integrations/src/shell/mod.rs +++ b/crates/fig_integrations/src/shell/mod.rs @@ -12,6 +12,7 @@ use fig_os_shim::Env; use fig_util::{ CLI_BINARY_NAME, PRODUCT_NAME, + PTY_BINARY_NAME, Shell, directories, }; @@ -97,7 +98,7 @@ pub trait ShellExt { fn get_shell_integrations(&self, env: &Env) -> Result>>; /// Script integrations are installed into ~/.fig/shell fn get_script_integrations(&self) -> Result>; - fn get_fig_integration_source(&self, when: &When) -> &'static str; + fn get_fig_integration_source(&self, when: &When) -> String; } impl ShellExt for Shell { @@ -186,8 +187,8 @@ impl ShellExt for Shell { Ok(integrations) } - fn get_fig_integration_source(&self, when: &When) -> &'static str { - match (self, when) { + fn get_fig_integration_source(&self, when: &When) -> String { + let script = match (self, when) { (Shell::Fish, When::Pre) => include_str!("scripts/pre.fish"), (Shell::Fish, When::Post) => include_str!("scripts/post.fish"), (Shell::Zsh, When::Pre) => include_str!("scripts/pre.sh"), @@ -216,7 +217,11 @@ impl ShellExt for Shell { }, (Shell::Nu, When::Pre) => include_str!("scripts/pre.nu"), (Shell::Nu, When::Post) => include_str!("scripts/post.nu"), - } + }; + + script + .replace("{{CLI_BINARY_NAME}}", CLI_BINARY_NAME) + .replace("{{PTY_BINARY_NAME}}", PTY_BINARY_NAME) } } @@ -814,7 +819,7 @@ mod test { } fn check_script(shell: Shell, when: When) { - run_shellcheck(shell.get_fig_integration_source(&when).to_owned()); + run_shellcheck(shell.get_fig_integration_source(&when)); } #[test] diff --git a/crates/fig_integrations/src/shell/scripts/post.bash b/crates/fig_integrations/src/shell/scripts/post.bash index 84f8f1516..f4f5fb78a 100644 --- a/crates/fig_integrations/src/shell/scripts/post.bash +++ b/crates/fig_integrations/src/shell/scripts/post.bash @@ -17,7 +17,7 @@ Q_LAST_PS2="$PS2" Q_LAST_PS3="$PS3" if [[ -z "${Q_SHELL:-}" ]]; then - Q_SHELL=$(q _ get-shell) + Q_SHELL=$({{CLI_BINARY_NAME}} _ get-shell) fi # Construct Operating System Command. @@ -68,8 +68,8 @@ function __fig_pre_prompt () { fig_osc "Log=%s" "${Q_LOG_LEVEL}" fig_osc "User=%s" "${USER:-root}" - if command -v q >/dev/null 2>&1; then - (command q _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1 + if command -v {{CLI_BINARY_NAME}} >/dev/null 2>&1; then + (command {{CLI_BINARY_NAME}} _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1 fi # Work around bug in CentOS 7.2 where preexec doesn't run if you press ^C @@ -180,4 +180,4 @@ fi fi -(command q _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1 +(command {{CLI_BINARY_NAME}} _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1 diff --git a/crates/fig_integrations/src/shell/scripts/post.fish b/crates/fig_integrations/src/shell/scripts/post.fish index 3ae27eaba..a436c83ff 100644 --- a/crates/fig_integrations/src/shell/scripts/post.fish +++ b/crates/fig_integrations/src/shell/scripts/post.fish @@ -6,7 +6,7 @@ set --export TTY set --export SHELL_PID $fish_pid -set --query Q_SHELL; or set Q_SHELL (q _ get-shell) +set --query Q_SHELL; or set Q_SHELL ({{CLI_BINARY_NAME}} _ get-shell) function fig_osc builtin printf "\033]697;$argv[1]\007" $argv[2..-1] @@ -98,8 +98,8 @@ function fig_precmd --on-event fish_prompt set fig_has_set_prompt 1 - if command -v q &>/dev/null - begin; command q _ pre-cmd --alias (alias) &> /dev/null &; end + if command -v {{CLI_BINARY_NAME}} &>/dev/null + begin; command {{CLI_BINARY_NAME}} _ pre-cmd --alias (alias) &> /dev/null &; end end end @@ -109,4 +109,4 @@ if test -n "$PROCESS_LAUNCHED_BY_Q" fig_osc DoneSourcing end -begin; command q _ pre-cmd --alias (alias) &> /dev/null &; end +begin; command {{CLI_BINARY_NAME}} _ pre-cmd --alias (alias) &> /dev/null &; end diff --git a/crates/fig_integrations/src/shell/scripts/post.nu b/crates/fig_integrations/src/shell/scripts/post.nu index caea4a0e6..b0c6a0031 100644 --- a/crates/fig_integrations/src/shell/scripts/post.nu +++ b/crates/fig_integrations/src/shell/scripts/post.nu @@ -7,7 +7,7 @@ def pathadd [path: string] { } let-env PATH = pathadd $"($env.HOME)/.local/bin" -let-env Q_SHELL = (^q _ get-shell) +let-env Q_SHELL = (^{{CLI_BINARY_NAME}} _ get-shell) let-env PATH = $env.PATH @@ -143,7 +143,7 @@ def-env fig_pre_prompt_hook [] { # } if (which fig | length) >= 1 { - let result = (q _ pre-cmd | complete) + let result = ({{CLI_BINARY_NAME}} _ pre-cmd | complete) if $result.stdout == "EXEC_NEW_SHELL" { let-env Q_DOTFILES_SOURCED = $nothing exec nu @@ -208,4 +208,4 @@ if "PROCESS_LAUNCHED_BY_Q" in $env { print_fig_osc "DoneSourcing" } -(^q _ pre-cmd | complete | ignore) +(^{{CLI_BINARY_NAME}} _ pre-cmd | complete | ignore) diff --git a/crates/fig_integrations/src/shell/scripts/post.zsh b/crates/fig_integrations/src/shell/scripts/post.zsh index 9d4cf5193..40f80b758 100644 --- a/crates/fig_integrations/src/shell/scripts/post.zsh +++ b/crates/fig_integrations/src/shell/scripts/post.zsh @@ -13,7 +13,7 @@ export TTY export SHELL_PID="$$" if [[ -z "${Q_SHELL:-}" ]]; then - Q_SHELL=$(q _ get-shell) + Q_SHELL=$({{CLI_BINARY_NAME}} _ get-shell) fi # shellcheck disable=SC2059 @@ -165,8 +165,8 @@ fig_precmd() { Q_HAS_SET_PROMPT=1 - if command -v q >/dev/null 2>&1; then - (command q _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1 + if command -v {{CLI_BINARY_NAME}} >/dev/null 2>&1; then + (command {{CLI_BINARY_NAME}} _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1 fi } @@ -190,4 +190,4 @@ fi fi -(command q _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1 +(command {{CLI_BINARY_NAME}} _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1 diff --git a/crates/fig_integrations/src/shell/scripts/pre.fish b/crates/fig_integrations/src/shell/scripts/pre.fish index 0c57e942e..116e4ee0b 100644 --- a/crates/fig_integrations/src/shell/scripts/pre.fish +++ b/crates/fig_integrations/src/shell/scripts/pre.fish @@ -16,31 +16,31 @@ end if test -z "$SHOULD_QTERM_LAUNCH" # 0 = Yes, 1 = No, 2 = Fallback to Q_TERM - q _ should-figterm-launch 1>/dev/null 2>&1 + {{CLI_BINARY_NAME}} _ should-figterm-launch 1>/dev/null 2>&1 set SHOULD_QTERM_LAUNCH $status end if test -t 1 and test -z "$PROCESS_LAUNCHED_BY_Q" - and command -v qterm 1>/dev/null 2>/dev/null + and command -v {{PTY_BINARY_NAME}} 1>/dev/null 2>/dev/null and test "$SHOULD_QTERM_LAUNCH" -eq 0 -o \( "$SHOULD_QTERM_LAUNCH" -eq 2 -a \( -z "$Q_TERM" -o \( -z "$Q_TERM_TMUX" -a -n "$TMUX" \) \) \) if test -z "$Q_SHELL" - set Q_SHELL (q _ get-shell) + set Q_SHELL ({{CLI_BINARY_NAME}} _ get-shell) end set Q_IS_LOGIN_SHELL 0 if status --is-login set Q_IS_LOGIN_SHELL 1 end - # Do not launch qterm in non-interactive shells (like VSCode Tasks) + # Do not launch {{PTY_BINARY_NAME}} in non-interactive shells (like VSCode Tasks) if status --is-interactive - set Q_TERM_NAME (command basename "$Q_SHELL")" (qterm)" + set Q_TERM_NAME (command basename "$Q_SHELL")" ({{PTY_BINARY_NAME}})" if not set -q Q_TERM_PATH if test -x "$HOME/.local/bin/$Q_TERM_NAME" set Q_TERM_PATH "$HOME/.local/bin/$Q_TERM_NAME" else - set Q_TERM_PATH (command -v qterm || echo "$HOME/.local/bin/qterm") + set Q_TERM_PATH (command -v {{PTY_BINARY_NAME}} || echo "$HOME/.local/bin/{{PTY_BINARY_NAME}}") end end diff --git a/crates/fig_integrations/src/shell/scripts/pre.nu b/crates/fig_integrations/src/shell/scripts/pre.nu index 7df4c3300..240764707 100644 --- a/crates/fig_integrations/src/shell/scripts/pre.nu +++ b/crates/fig_integrations/src/shell/scripts/pre.nu @@ -26,7 +26,7 @@ if "Q_SET_PARENT_CHECK" not-in $env { } -let result = (^q _ should-figterm-launch | complete) +let result = (^{{CLI_BINARY_NAME}} _ should-figterm-launch | complete) let-env SHOULD_QTERM_LAUNCH = $result.exit_code let should_launch = ( @@ -36,7 +36,7 @@ let should_launch = ( ) if $should_launch { - let Q_SHELL = (q _ get-shell | complete).stdout + let Q_SHELL = ({{CLI_BINARY_NAME}} _ get-shell | complete).stdout let fig_term_name = "nu (figterm)" let figterm_path = if ([$env.HOME ".fig" "bin" $fig_term_name] | path join | path exists) { diff --git a/crates/fig_integrations/src/shell/scripts/pre.sh b/crates/fig_integrations/src/shell/scripts/pre.sh index 260859fe3..0ab263358 100644 --- a/crates/fig_integrations/src/shell/scripts/pre.sh +++ b/crates/fig_integrations/src/shell/scripts/pre.sh @@ -24,7 +24,7 @@ fi # 0 = Yes, 1 = No, 2 = Fallback to Q_TERM if [ -z "${SHOULD_QTERM_LAUNCH:-}" ]; then - q _ should-figterm-launch 1>/dev/null 2>&1 + {{CLI_BINARY_NAME}} _ should-figterm-launch 1>/dev/null 2>&1 SHOULD_QTERM_LAUNCH=$? fi @@ -33,12 +33,12 @@ fi # It is not necessary in Fish. if [[ -t 1 ]] \ && [[ -z "${PROCESS_LAUNCHED_BY_Q:-}" ]] \ - && command -v qterm 1>/dev/null 2>&1 \ + && command -v {{PTY_BINARY_NAME}} 1>/dev/null 2>&1 \ && [[ ("${SHOULD_QTERM_LAUNCH}" -eq 0) || (("${SHOULD_QTERM_LAUNCH}" -eq 2) && (-z "${Q_TERM:-}" || (-z "${Q_TERM_TMUX:-}" && -n "${TMUX:-}"))) ]] then # Pty module sets Q_TERM or Q_TERM_TMUX to avoid running twice. if [ -z "${Q_SHELL:-}" ]; then - Q_SHELL=$(q _ get-shell) + Q_SHELL=$({{CLI_BINARY_NAME}} _ get-shell) fi Q_IS_LOGIN_SHELL="${Q_IS_LOGIN_SHELL:='0'}" @@ -50,12 +50,12 @@ then # Do not launch figterm in non-interactive shells (like VSCode Tasks) if [[ $- == *i* ]]; then - Q_TERM_NAME="$(basename "${Q_SHELL}") (qterm)" + Q_TERM_NAME="$(basename "${Q_SHELL}") ({{PTY_BINARY_NAME}})" if [[ -z "${Q_TERM_PATH:-}" ]]; then if [[ -x "${HOME}/.local/bin/${Q_TERM_NAME}" ]]; then Q_TERM_PATH="${HOME}/.local/bin/${Q_TERM_NAME}" else - Q_TERM_PATH="$(command -v qterm || echo "${HOME}/.local/bin/qterm")" + Q_TERM_PATH="$(command -v {{PTY_BINARY_NAME}} || echo "${HOME}/.local/bin/{{PTY_BINARY_NAME}}")" fi fi diff --git a/crates/q_cli/src/cli/init.rs b/crates/q_cli/src/cli/init.rs index 16ebeef32..cb8f64583 100644 --- a/crates/q_cli/src/cli/init.rs +++ b/crates/q_cli/src/cli/init.rs @@ -204,7 +204,7 @@ async fn shell_init(shell: &Shell, when: &When, rcfile: &Option) -> Resu } let shell_integration_source = shell.get_fig_integration_source(when); - to_source.push(shell_integration_source.into()); + to_source.push(shell_integration_source); if when == &When::Pre && is_jetbrains_terminal { // Manually call JetBrains shell integration after exec-ing to figterm. From b40f48636afceb0782f4d6207a90d9cdf33fa0a7 Mon Sep 17 00:00:00 2001 From: kkashilk Date: Wed, 29 Oct 2025 14:55:39 -0700 Subject: [PATCH 2/4] feat(shell): Parameterize binary names in inline shell completion - Add {{CLI_BINARY_NAME}} and {{CLI_BINARY_NAME_UPPER}} placeholders to all inline shell completion .zsh files - Update build.rs to perform runtime substitution of placeholders - Replace all _q_ function prefixes with _{{CLI_BINARY_NAME}}_ - Replace all _Q_ and Q_ variable prefixes with _{{CLI_BINARY_NAME_UPPER}}_ and {{CLI_BINARY_NAME_UPPER}}_ - Replace hardcoded 'q' binary commands with {{CLI_BINARY_NAME}} - Add CLI_BINARY_NAME constant at top of build.rs This enables changing binary names by updating constants in one place. --- crates/fig_integrations/build.rs | 10 +++ .../shell/inline_shell_completion/async.zsh | 26 +++--- .../shell/inline_shell_completion/bind.zsh | 60 +++++++------- .../shell/inline_shell_completion/config.zsh | 48 +++++------ .../shell/inline_shell_completion/fetch.zsh | 6 +- .../inline_shell_completion/guard_start.zsh | 2 +- .../inline_shell_completion/highlight.zsh | 20 ++--- .../shell/inline_shell_completion/start.zsh | 14 ++-- .../strategies/completion.zsh | 32 ++++---- .../strategies/history.zsh | 6 +- .../strategies/inline.zsh | 4 +- .../strategies/match_prev_cmd.zsh | 8 +- .../shell/inline_shell_completion/util.zsh | 2 +- .../shell/inline_shell_completion/widgets.zsh | 82 +++++++++---------- 14 files changed, 165 insertions(+), 155 deletions(-) diff --git a/crates/fig_integrations/build.rs b/crates/fig_integrations/build.rs index 768cc3d90..30b351def 100644 --- a/crates/fig_integrations/build.rs +++ b/crates/fig_integrations/build.rs @@ -1,5 +1,8 @@ const CODEX_FOLDER: &str = "src/shell/inline_shell_completion"; +// Binary name constants for parameterization +const CLI_BINARY_NAME: &str = "q"; + // The order here is very specific, do no edit without understanding the implications const CODEX_FILES: &[&str] = &[ "guard_start.zsh", @@ -31,5 +34,12 @@ fn main() { println!("cargo:rerun-if-changed={}", path.display()); inline_shell_completion.push_str(&std::fs::read_to_string(path).unwrap()); } + + // Substitute placeholders with actual binary names + let cli_binary_name_upper = CLI_BINARY_NAME.to_uppercase(); + inline_shell_completion = inline_shell_completion + .replace("{{CLI_BINARY_NAME}}", CLI_BINARY_NAME) + .replace("{{CLI_BINARY_NAME_UPPER}}", &cli_binary_name_upper); + std::fs::write(out_dir.join("inline_shell_completion.zsh"), inline_shell_completion).unwrap(); } diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/async.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/async.zsh index 5128c1aa3..3b8bd826c 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/async.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/async.zsh @@ -3,42 +3,42 @@ # Async # #--------------------------------------------------------------------# -_q_autosuggest_async_request() { +_{{CLI_BINARY_NAME}}_autosuggest_async_request() { zmodload zsh/system 2>/dev/null # For `$sysparams` - typeset -g _Q_AUTOSUGGEST_ASYNC_FD _Q_AUTOSUGGEST_CHILD_PID + typeset -g _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ASYNC_FD _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_CHILD_PID # If we've got a pending request, cancel it - if [[ -n "$_Q_AUTOSUGGEST_ASYNC_FD" ]] && { true <&$_Q_AUTOSUGGEST_ASYNC_FD } 2>/dev/null; then + if [[ -n "$_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ASYNC_FD" ]] && { true <&$_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ASYNC_FD } 2>/dev/null; then # Close the file descriptor and remove the handler - exec {_Q_AUTOSUGGEST_ASYNC_FD}<&- - zle -F $_Q_AUTOSUGGEST_ASYNC_FD + exec {_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ASYNC_FD}<&- + zle -F $_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ASYNC_FD # We won't know the pid unless the user has zsh/system module installed - if [[ -n "$_Q_AUTOSUGGEST_CHILD_PID" ]]; then + if [[ -n "$_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_CHILD_PID" ]]; then # Zsh will make a new process group for the child process only if job # control is enabled (MONITOR option) if [[ -o MONITOR ]]; then # Send the signal to the process group to kill any processes that may # have been forked by the suggestion strategy - kill -TERM -$_Q_AUTOSUGGEST_CHILD_PID 2>/dev/null + kill -TERM -$_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_CHILD_PID 2>/dev/null else # Kill just the child process since it wasn't placed in a new process # group. If the suggestion strategy forked any child processes they may # be orphaned and left behind. - kill -TERM $_Q_AUTOSUGGEST_CHILD_PID 2>/dev/null + kill -TERM $_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_CHILD_PID 2>/dev/null fi fi fi # Fork a process to fetch a suggestion and open a pipe to read from it - exec {_Q_AUTOSUGGEST_ASYNC_FD}< <( + exec {_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ASYNC_FD}< <( # Tell parent process our pid echo $sysparams[pid] # Fetch and print the suggestion local suggestion - _q_autosuggest_fetch_suggestion "$1" + _{{CLI_BINARY_NAME}}_autosuggest_fetch_suggestion "$1" echo -nE "$suggestion" ) @@ -48,16 +48,16 @@ _q_autosuggest_async_request() { is-at-least 5.8 || command true # Read the pid from the child process - read _Q_AUTOSUGGEST_CHILD_PID <&$_Q_AUTOSUGGEST_ASYNC_FD + read _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_CHILD_PID <&$_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ASYNC_FD # When the fd is readable, call the response handler - zle -F "$_Q_AUTOSUGGEST_ASYNC_FD" _q_autosuggest_async_response + zle -F "$_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ASYNC_FD" _{{CLI_BINARY_NAME}}_autosuggest_async_response } # Called when new data is ready to be read from the pipe # First arg will be fd ready for reading # Second arg will be passed in case of error -_q_autosuggest_async_response() { +_{{CLI_BINARY_NAME}}_autosuggest_async_response() { emulate -L zsh local suggestion diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/bind.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/bind.zsh index 11619661e..eaccd62d4 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/bind.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/bind.zsh @@ -3,44 +3,44 @@ # Widget Helpers # #--------------------------------------------------------------------# -_q_autosuggest_incr_bind_count() { - typeset -gi bind_count=$((_Q_AUTOSUGGEST_BIND_COUNTS[$1]+1)) - _Q_AUTOSUGGEST_BIND_COUNTS[$1]=$bind_count +_{{CLI_BINARY_NAME}}_autosuggest_incr_bind_count() { + typeset -gi bind_count=$((_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BIND_COUNTS[$1]+1)) + _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BIND_COUNTS[$1]=$bind_count } # Bind a single widget to an autosuggest widget, saving a reference to the original widget -_q_autosuggest_bind_widget() { - typeset -gA _Q_AUTOSUGGEST_BIND_COUNTS +_{{CLI_BINARY_NAME}}_autosuggest_bind_widget() { + typeset -gA _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BIND_COUNTS local widget=$1 local autosuggest_action=$2 - local prefix=$Q_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX + local prefix=${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX local -i bind_count # Save a reference to the original widget case $widgets[$widget] in # Already bound - user:_q_autosuggest_(bound|orig)_*) - bind_count=$((_Q_AUTOSUGGEST_BIND_COUNTS[$widget])) + user:_{{CLI_BINARY_NAME}}_autosuggest_(bound|orig)_*) + bind_count=$((_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BIND_COUNTS[$widget])) ;; # User-defined widget user:*) - _q_autosuggest_incr_bind_count $widget + _{{CLI_BINARY_NAME}}_autosuggest_incr_bind_count $widget zle -N $prefix$bind_count-$widget ${widgets[$widget]#*:} ;; # Built-in widget builtin) - _q_autosuggest_incr_bind_count $widget - eval "_q_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }" - zle -N $prefix$bind_count-$widget _q_autosuggest_orig_$widget + _{{CLI_BINARY_NAME}}_autosuggest_incr_bind_count $widget + eval "_{{CLI_BINARY_NAME}}_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }" + zle -N $prefix$bind_count-$widget _{{CLI_BINARY_NAME}}_autosuggest_orig_$widget ;; # Completion widget completion:*) - _q_autosuggest_incr_bind_count $widget + _{{CLI_BINARY_NAME}}_autosuggest_incr_bind_count $widget eval "zle -C $prefix$bind_count-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}" ;; esac @@ -51,16 +51,16 @@ _q_autosuggest_bind_widget() { # correctly. $WIDGET cannot be trusted because other plugins call # zle without the `-w` flag (e.g. `zle self-insert` instead of # `zle self-insert -w`). - eval "_q_autosuggest_bound_${bind_count}_${(q)widget}() { - _q_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@ + eval "_{{CLI_BINARY_NAME}}_autosuggest_bound_${bind_count}_${(q)widget}() { + _{{CLI_BINARY_NAME}}_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@ }" # Create the bound widget - zle -N -- $widget _q_autosuggest_bound_${bind_count}_$widget + zle -N -- $widget _{{CLI_BINARY_NAME}}_autosuggest_bound_${bind_count}_$widget } # Map all configured widgets to the right autosuggest widgets -_q_autosuggest_bind_widgets() { +_{{CLI_BINARY_NAME}}_autosuggest_bind_widgets() { emulate -L zsh local widget @@ -69,30 +69,30 @@ _q_autosuggest_bind_widgets() { ignore_widgets=( .\* _\* - ${_Q_AUTOSUGGEST_BUILTIN_ACTIONS/#/autosuggest-} - $Q_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\* - $Q_AUTOSUGGEST_IGNORE_WIDGETS + ${_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BUILTIN_ACTIONS/#/autosuggest-} + ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\* + ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_IGNORE_WIDGETS ) # Find every widget we might want to bind and bind it appropriately for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do - if [[ -n ${Q_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then - _q_autosuggest_bind_widget $widget clear - elif [[ -n ${Q_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then - _q_autosuggest_bind_widget $widget accept - elif [[ -n ${Q_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then - _q_autosuggest_bind_widget $widget execute - elif [[ -n ${Q_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then - _q_autosuggest_bind_widget $widget partial_accept + if [[ -n ${{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then + _{{CLI_BINARY_NAME}}_autosuggest_bind_widget $widget clear + elif [[ -n ${{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then + _{{CLI_BINARY_NAME}}_autosuggest_bind_widget $widget accept + elif [[ -n ${{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then + _{{CLI_BINARY_NAME}}_autosuggest_bind_widget $widget execute + elif [[ -n ${{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then + _{{CLI_BINARY_NAME}}_autosuggest_bind_widget $widget partial_accept else # Assume any unspecified widget might modify the buffer - _q_autosuggest_bind_widget $widget modify + _{{CLI_BINARY_NAME}}_autosuggest_bind_widget $widget modify fi done } # Given the name of an original widget and args, invoke it, if it exists -_q_autosuggest_invoke_original_widget() { +_{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget() { # Do nothing unless called with at least one arg (( $# )) || return 0 diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/config.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/config.zsh index b15fef364..9bd8c5963 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/config.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/config.zsh @@ -6,24 +6,24 @@ # Color to use when highlighting suggestion # Uses format of `region_highlight` # More info: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Widgets -(( ! ${+Q_AUTOSUGGEST_HIGHLIGHT_STYLE} )) && -typeset -g Q_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8' +(( ! ${+{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_HIGHLIGHT_STYLE} )) && +typeset -g {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8' # Prefix to use when saving original versions of bound widgets -(( ! ${+Q_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX} )) && -typeset -g Q_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- +(( ! ${+{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX} )) && +typeset -g {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- # Strategies to use to fetch a suggestion # Will try each strategy in order until a suggestion is returned -(( ! ${+Q_AUTOSUGGEST_STRATEGY} )) && { - typeset -ga Q_AUTOSUGGEST_STRATEGY - Q_AUTOSUGGEST_STRATEGY=(inline_shell_completion) +(( ! ${+{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_STRATEGY} )) && { + typeset -ga {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_STRATEGY + {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_STRATEGY=(inline_shell_completion) } # Widgets that clear the suggestion -(( ! ${+Q_AUTOSUGGEST_CLEAR_WIDGETS} )) && { - typeset -ga Q_AUTOSUGGEST_CLEAR_WIDGETS - Q_AUTOSUGGEST_CLEAR_WIDGETS=( +(( ! ${+{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_CLEAR_WIDGETS} )) && { + typeset -ga {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_CLEAR_WIDGETS + {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_CLEAR_WIDGETS=( history-search-forward history-search-backward history-beginning-search-forward @@ -40,9 +40,9 @@ typeset -g Q_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- } # Widgets that accept the entire suggestion -(( ! ${+Q_AUTOSUGGEST_ACCEPT_WIDGETS} )) && { - typeset -ga Q_AUTOSUGGEST_ACCEPT_WIDGETS - Q_AUTOSUGGEST_ACCEPT_WIDGETS=( +(( ! ${+{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ACCEPT_WIDGETS} )) && { + typeset -ga {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ACCEPT_WIDGETS + {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ACCEPT_WIDGETS=( forward-char end-of-line vi-forward-char @@ -52,16 +52,16 @@ typeset -g Q_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- } # Widgets that accept the entire suggestion and execute it -(( ! ${+Q_AUTOSUGGEST_EXECUTE_WIDGETS} )) && { - typeset -ga Q_AUTOSUGGEST_EXECUTE_WIDGETS - Q_AUTOSUGGEST_EXECUTE_WIDGETS=( +(( ! ${+{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_EXECUTE_WIDGETS} )) && { + typeset -ga {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_EXECUTE_WIDGETS + {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_EXECUTE_WIDGETS=( ) } # Widgets that accept the suggestion as far as the cursor moves -(( ! ${+Q_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS} )) && { - typeset -ga Q_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS - Q_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=( +(( ! ${+{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS} )) && { + typeset -ga {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS + {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=( forward-word emacs-forward-word vi-forward-word @@ -74,9 +74,9 @@ typeset -g Q_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- } # Widgets that should be ignored (globbing supported but must be escaped) -(( ! ${+Q_AUTOSUGGEST_IGNORE_WIDGETS} )) && { - typeset -ga Q_AUTOSUGGEST_IGNORE_WIDGETS - Q_AUTOSUGGEST_IGNORE_WIDGETS=( +(( ! ${+{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_IGNORE_WIDGETS} )) && { + typeset -ga {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_IGNORE_WIDGETS + {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_IGNORE_WIDGETS=( orig-\* beep run-help @@ -89,5 +89,5 @@ typeset -g Q_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig- } # Pty name for capturing completions for completion suggestion strategy -(( ! ${+Q_AUTOSUGGEST_COMPLETIONS_PTY_NAME} )) && -typeset -g Q_AUTOSUGGEST_COMPLETIONS_PTY_NAME=q_autosuggest_completion_pty +(( ! ${+{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETIONS_PTY_NAME} )) && +typeset -g {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETIONS_PTY_NAME=q_autosuggest_completion_pty diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/fetch.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/fetch.zsh index d55fe1867..68aa42b26 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/fetch.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/fetch.zsh @@ -6,17 +6,17 @@ # from the first strategy to provide one. # -_q_autosuggest_fetch_suggestion() { +_{{CLI_BINARY_NAME}}_autosuggest_fetch_suggestion() { typeset -g suggestion local -a strategies local strategy # Ensure we are working with an array - strategies=(${=Q_AUTOSUGGEST_STRATEGY}) + strategies=(${={{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_STRATEGY}) for strategy in $strategies; do # Try to get a suggestion from this strategy - _q_autosuggest_strategy_$strategy "$1" + _{{CLI_BINARY_NAME}}_autosuggest_strategy_$strategy "$1" # Ensure the suggestion matches the prefix [[ "$suggestion" != "$1"* ]] && unset suggestion diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/guard_start.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/guard_start.zsh index 97baf66fd..4c89c6469 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/guard_start.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/guard_start.zsh @@ -1,3 +1,3 @@ if command -v _zsh_autosuggest_accept >/dev/null 2>&1; then - export Q_USING_ZSH_AUTOSUGGESTIONS=1 + export {{CLI_BINARY_NAME_UPPER}}_USING_ZSH_AUTOSUGGESTIONS=1 else diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/highlight.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/highlight.zsh index b6d2df65f..34fe74f42 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/highlight.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/highlight.zsh @@ -4,23 +4,23 @@ #--------------------------------------------------------------------# # If there was a highlight, remove it -_q_autosuggest_highlight_reset() { - typeset -g _Q_AUTOSUGGEST_LAST_HIGHLIGHT +_{{CLI_BINARY_NAME}}_autosuggest_highlight_reset() { + typeset -g _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_LAST_HIGHLIGHT - if [[ -n "$_Q_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then - region_highlight=("${(@)region_highlight:#$_Q_AUTOSUGGEST_LAST_HIGHLIGHT}") - unset _Q_AUTOSUGGEST_LAST_HIGHLIGHT + if [[ -n "$_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then + region_highlight=("${(@)region_highlight:#$_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_LAST_HIGHLIGHT}") + unset _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_LAST_HIGHLIGHT fi } # If there's a suggestion, highlight it -_q_autosuggest_highlight_apply() { - typeset -g _Q_AUTOSUGGEST_LAST_HIGHLIGHT +_{{CLI_BINARY_NAME}}_autosuggest_highlight_apply() { + typeset -g _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_LAST_HIGHLIGHT if (( $#POSTDISPLAY )); then - typeset -g _Q_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $Q_AUTOSUGGEST_HIGHLIGHT_STYLE" - region_highlight+=("$_Q_AUTOSUGGEST_LAST_HIGHLIGHT") + typeset -g _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_HIGHLIGHT_STYLE" + region_highlight+=("$_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_LAST_HIGHLIGHT") else - unset _Q_AUTOSUGGEST_LAST_HIGHLIGHT + unset _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_LAST_HIGHLIGHT fi } diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/start.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/start.zsh index a0af6fd83..d3cf349c0 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/start.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/start.zsh @@ -4,18 +4,18 @@ #--------------------------------------------------------------------# # Start the autosuggestion widgets -_q_autosuggest_start() { +_{{CLI_BINARY_NAME}}_autosuggest_start() { # By default we re-bind widgets on every precmd to ensure we wrap other # wrappers. Specifically, highlighting breaks if our widgets are wrapped by # zsh-syntax-highlighting widgets. This also allows modifications to the # widget list variables to take effect on the next precmd. However this has - # a decent performance hit, so users can set Q_AUTOSUGGEST_MANUAL_REBIND + # a decent performance hit, so users can set {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_MANUAL_REBIND # to disable the automatic re-binding. - if (( ${+Q_AUTOSUGGEST_MANUAL_REBIND} )); then - add-zsh-hook -d precmd _q_autosuggest_start + if (( ${+{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_MANUAL_REBIND} )); then + add-zsh-hook -d precmd _{{CLI_BINARY_NAME}}_autosuggest_start fi - _q_autosuggest_bind_widgets + _{{CLI_BINARY_NAME}}_autosuggest_bind_widgets } # Mark for auto-loading the functions that we use @@ -26,8 +26,8 @@ autoload -Uz add-zsh-hook is-at-least # work immediately after fetching a suggestion. # See https://github.com/zsh-users/zsh-autosuggestions/issues/364 if is-at-least 5.0.8; then - typeset -g Q_AUTOSUGGEST_USE_ASYNC= + typeset -g {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_USE_ASYNC= fi # Start the autosuggestion widgets on the next precmd -add-zsh-hook precmd _q_autosuggest_start +add-zsh-hook precmd _{{CLI_BINARY_NAME}}_autosuggest_start diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/completion.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/completion.zsh index 99ba40132..78891d341 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/completion.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/completion.zsh @@ -5,7 +5,7 @@ # Fetches a suggestion from the completion engine # -_q_autosuggest_capture_postcompletion() { +_{{CLI_BINARY_NAME}}_autosuggest_capture_postcompletion() { # Always insert the first completion into the buffer compstate[insert]=1 @@ -13,12 +13,12 @@ _q_autosuggest_capture_postcompletion() { unset 'compstate[list]' } -_q_autosuggest_capture_completion_widget() { +_{{CLI_BINARY_NAME}}_autosuggest_capture_completion_widget() { # Add a post-completion hook to be called after all completions have been # gathered. The hook can modify compstate to affect what is done with the # gathered completions. local -a +h comppostfuncs - comppostfuncs=(_q_autosuggest_capture_postcompletion) + comppostfuncs=(_{{CLI_BINARY_NAME}}_autosuggest_capture_postcompletion) # Only capture completions at the end of the buffer CURSOR=$#BUFFER @@ -42,9 +42,9 @@ _q_autosuggest_capture_completion_widget() { echo -nE - $'\0'$BUFFER$'\0' } -zle -N autosuggest-capture-completion _q_autosuggest_capture_completion_widget +zle -N autosuggest-capture-completion _{{CLI_BINARY_NAME}}_autosuggest_capture_completion_widget -_q_autosuggest_capture_setup() { +_{{CLI_BINARY_NAME}}_autosuggest_capture_setup() { # There is a bug in zpty module in older zsh versions by which a # zpty that exits will kill all zpty processes that were forked # before it. Here we set up a zsh exit hook to SIGKILL the zpty @@ -69,14 +69,14 @@ _q_autosuggest_capture_setup() { bindkey '^I' autosuggest-capture-completion } -_q_autosuggest_capture_completion_sync() { - _q_autosuggest_capture_setup +_{{CLI_BINARY_NAME}}_autosuggest_capture_completion_sync() { + _{{CLI_BINARY_NAME}}_autosuggest_capture_setup zle autosuggest-capture-completion } -_q_autosuggest_capture_completion_async() { - _q_autosuggest_capture_setup +_{{CLI_BINARY_NAME}}_autosuggest_capture_completion_async() { + _{{CLI_BINARY_NAME}}_autosuggest_capture_setup zmodload zsh/parameter 2>/dev/null || return # For `$functions` @@ -93,7 +93,7 @@ _q_autosuggest_capture_completion_async() { vared 1 } -_q_autosuggest_strategy_completion() { +_{{CLI_BINARY_NAME}}_autosuggest_strategy_completion() { # Reset options to defaults and enable LOCAL_OPTIONS emulate -L zsh @@ -110,20 +110,20 @@ _q_autosuggest_strategy_completion() { zmodload zsh/zpty 2>/dev/null || return # Exit if our search string matches the ignore pattern - [[ -n "$Q_AUTOSUGGEST_COMPLETION_IGNORE" ]] && [[ "$1" == $~Q_AUTOSUGGEST_COMPLETION_IGNORE ]] && return + [[ -n "${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETION_IGNORE" ]] && [[ "$1" == $~{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETION_IGNORE ]] && return # Zle will be inactive if we are in async mode if zle; then - zpty $Q_AUTOSUGGEST_COMPLETIONS_PTY_NAME _q_autosuggest_capture_completion_sync + zpty ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETIONS_PTY_NAME _{{CLI_BINARY_NAME}}_autosuggest_capture_completion_sync else - zpty $Q_AUTOSUGGEST_COMPLETIONS_PTY_NAME _q_autosuggest_capture_completion_async "\$1" - zpty -w $Q_AUTOSUGGEST_COMPLETIONS_PTY_NAME $'\t' + zpty ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETIONS_PTY_NAME _{{CLI_BINARY_NAME}}_autosuggest_capture_completion_async "\$1" + zpty -w ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETIONS_PTY_NAME $'\t' fi { # The completion result is surrounded by null bytes, so read the # content between the first two null bytes. - zpty -r $Q_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\0' + zpty -r ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\0' # Extract the suggestion from between the null bytes. On older # versions of zsh (older than 5.3), we sometimes get extra bytes after @@ -132,6 +132,6 @@ _q_autosuggest_strategy_completion() { suggestion="${${(@0)line}[2]}" } always { # Destroy the pty - zpty -d $Q_AUTOSUGGEST_COMPLETIONS_PTY_NAME + zpty -d ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETIONS_PTY_NAME } } diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/history.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/history.zsh index d48b029bc..31cc1579d 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/history.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/history.zsh @@ -6,7 +6,7 @@ # prefix. # -_q_autosuggest_strategy_history() { +_{{CLI_BINARY_NAME}}_autosuggest_strategy_history() { # Reset options to defaults and enable LOCAL_OPTIONS emulate -L zsh @@ -22,8 +22,8 @@ _q_autosuggest_strategy_history() { # Get the history items that match the prefix, excluding those that match # the ignore pattern local pattern="$prefix*" - if [[ -n $Q_AUTOSUGGEST_HISTORY_IGNORE ]]; then - pattern="($pattern)~($Q_AUTOSUGGEST_HISTORY_IGNORE)" + if [[ -n ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_HISTORY_IGNORE ]]; then + pattern="($pattern)~(${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_HISTORY_IGNORE)" fi # Give the first history item matching the pattern as the suggestion diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/inline.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/inline.zsh index 30e6c0bee..e031c0d07 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/inline.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/inline.zsh @@ -5,6 +5,6 @@ # Suggests the inline_shell_completion command. # -_q_autosuggest_strategy_inline_shell_completion() { - typeset -g suggestion="$(command -v q >/dev/null 2>&1 && q _ inline-shell-completion --buffer "${BUFFER}")" +_{{CLI_BINARY_NAME}}_autosuggest_strategy_inline_shell_completion() { + typeset -g suggestion="$(command -v {{CLI_BINARY_NAME}} >/dev/null 2>&1 && {{CLI_BINARY_NAME}} _ inline-shell-completion --buffer "${BUFFER}")" } diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/match_prev_cmd.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/match_prev_cmd.zsh index 053601534..6011d7c2b 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/match_prev_cmd.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/match_prev_cmd.zsh @@ -20,7 +20,7 @@ # preserve the history order such as `HIST_IGNORE_ALL_DUPS` or # `HIST_EXPIRE_DUPS_FIRST`. -_q_autosuggest_strategy_match_prev_cmd() { +_{{CLI_BINARY_NAME}}_autosuggest_strategy_match_prev_cmd() { # Reset options to defaults and enable LOCAL_OPTIONS emulate -L zsh @@ -33,8 +33,8 @@ _q_autosuggest_strategy_match_prev_cmd() { # Get the history items that match the prefix, excluding those that match # the ignore pattern local pattern="$prefix*" - if [[ -n $Q_AUTOSUGGEST_HISTORY_IGNORE ]]; then - pattern="($pattern)~($Q_AUTOSUGGEST_HISTORY_IGNORE)" + if [[ -n ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_HISTORY_IGNORE ]]; then + pattern="($pattern)~(${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_HISTORY_IGNORE)" fi # Get all history event numbers that correspond to history @@ -46,7 +46,7 @@ _q_autosuggest_strategy_match_prev_cmd() { local histkey="${history_match_keys[1]}" # Get the previously executed command - local prev_cmd="$(_q_autosuggest_escape_command "${history[$((HISTCMD-1))]}")" + local prev_cmd="$(_{{CLI_BINARY_NAME}}_autosuggest_escape_command "${history[$((HISTCMD-1))]}")" # Iterate up to the first 200 history event numbers that match $prefix for key in "${(@)history_match_keys[1,200]}"; do diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/util.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/util.zsh index c3b7345a1..cd8bd211e 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/util.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/util.zsh @@ -3,7 +3,7 @@ # Utility Functions # #--------------------------------------------------------------------# -_q_autosuggest_escape_command() { +_{{CLI_BINARY_NAME}}_autosuggest_escape_command() { setopt localoptions EXTENDED_GLOB # Escape special chars in the string (requires EXTENDED_GLOB) diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/widgets.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/widgets.zsh index ac6f8bdf2..3c359b4fe 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/widgets.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/widgets.zsh @@ -4,39 +4,39 @@ #--------------------------------------------------------------------# # Disable suggestions -_q_autosuggest_disable() { - typeset -g _Q_AUTOSUGGEST_DISABLED - _q_autosuggest_clear +_{{CLI_BINARY_NAME}}_autosuggest_disable() { + typeset -g _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_DISABLED + _{{CLI_BINARY_NAME}}_autosuggest_clear } # Enable suggestions -_q_autosuggest_enable() { - unset _Q_AUTOSUGGEST_DISABLED +_{{CLI_BINARY_NAME}}_autosuggest_enable() { + unset _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_DISABLED if (( $#BUFFER )); then - _q_autosuggest_fetch + _{{CLI_BINARY_NAME}}_autosuggest_fetch fi } # Toggle suggestions (enable/disable) -_q_autosuggest_toggle() { - if (( ${+_Q_AUTOSUGGEST_DISABLED} )); then - _q_autosuggest_enable +_{{CLI_BINARY_NAME}}_autosuggest_toggle() { + if (( ${+_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_DISABLED} )); then + _{{CLI_BINARY_NAME}}_autosuggest_enable else - _q_autosuggest_disable + _{{CLI_BINARY_NAME}}_autosuggest_disable fi } # Clear the suggestion -_q_autosuggest_clear() { +_{{CLI_BINARY_NAME}}_autosuggest_clear() { # Remove the suggestion unset POSTDISPLAY - _q_autosuggest_invoke_original_widget $@ + _{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget $@ } # Modify the buffer and get a new suggestion -_q_autosuggest_modify() { +_{{CLI_BINARY_NAME}}_autosuggest_modify() { local -i retval # Only available in zsh >= 5.4 @@ -50,7 +50,7 @@ _q_autosuggest_modify() { unset POSTDISPLAY # Original widget may modify the buffer - _q_autosuggest_invoke_original_widget $@ + _{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget $@ retval=$? emulate -L zsh @@ -68,14 +68,14 @@ _q_autosuggest_modify() { fi # Bail out if suggestions are disabled - if (( ${+_Q_AUTOSUGGEST_DISABLED} )); then + if (( ${+_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_DISABLED} )); then return $? fi # Get a new suggestion if the buffer is not empty after modification if (( $#BUFFER > 0 )); then - if [[ -z "$Q_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $Q_AUTOSUGGEST_BUFFER_MAX_SIZE )); then - _q_autosuggest_fetch + if [[ -z "${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BUFFER_MAX_SIZE )); then + _{{CLI_BINARY_NAME}}_autosuggest_fetch fi fi @@ -83,18 +83,18 @@ _q_autosuggest_modify() { } # Fetch a new suggestion based on what's currently in the buffer -_q_autosuggest_fetch() { - if (( ${+Q_AUTOSUGGEST_USE_ASYNC} )); then - _q_autosuggest_async_request "$BUFFER" +_{{CLI_BINARY_NAME}}_autosuggest_fetch() { + if (( ${+{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_USE_ASYNC} )); then + _{{CLI_BINARY_NAME}}_autosuggest_async_request "$BUFFER" else local suggestion - _q_autosuggest_fetch_suggestion "$BUFFER" - _q_autosuggest_suggest "$suggestion" + _{{CLI_BINARY_NAME}}_autosuggest_fetch_suggestion "$BUFFER" + _{{CLI_BINARY_NAME}}_autosuggest_suggest "$suggestion" fi } # Offer a suggestion -_q_autosuggest_suggest() { +_{{CLI_BINARY_NAME}}_autosuggest_suggest() { emulate -L zsh local suggestion="$1" @@ -107,7 +107,7 @@ _q_autosuggest_suggest() { } # Accept the entire suggestion -_q_autosuggest_accept() { +_{{CLI_BINARY_NAME}}_autosuggest_accept() { local -i retval max_cursor_pos=$#BUFFER # When vicmd keymap is active, the cursor can't move all the way @@ -119,11 +119,11 @@ _q_autosuggest_accept() { # If we're not in a valid state to accept a suggestion, just run the # original widget and bail out if (( $CURSOR != $max_cursor_pos || !$#POSTDISPLAY )); then - _q_autosuggest_invoke_original_widget $@ + _{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget $@ return fi - (q _ inline-shell-completion-accept --buffer "$BUFFER" --suggestion "$POSTDISPLAY" > /dev/null 2>&1 &) + ({{CLI_BINARY_NAME}} _ inline-shell-completion-accept --buffer "$BUFFER" --suggestion "$POSTDISPLAY" > /dev/null 2>&1 &) # Only accept if the cursor is at the end of the buffer # Add the suggestion to the buffer @@ -134,7 +134,7 @@ _q_autosuggest_accept() { # Run the original widget before manually moving the cursor so that the # cursor movement doesn't make the widget do something unexpected - _q_autosuggest_invoke_original_widget $@ + _{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget $@ retval=$? # Move the cursor to the end of the buffer @@ -148,9 +148,9 @@ _q_autosuggest_accept() { } # Accept the entire suggestion and execute it -_q_autosuggest_execute() { +_{{CLI_BINARY_NAME}}_autosuggest_execute() { # background so we don't block the terminal - (q _ inline-shell-completion-accept --buffer "$BUFFER" --suggestion "$POSTDISPLAY" > /dev/null 2>&1 &) + ({{CLI_BINARY_NAME}} _ inline-shell-completion-accept --buffer "$BUFFER" --suggestion "$POSTDISPLAY" > /dev/null 2>&1 &) # Add the suggestion to the buffer BUFFER="$BUFFER$POSTDISPLAY" @@ -160,11 +160,11 @@ _q_autosuggest_execute() { # Call the original `accept-line` to handle syntax highlighting or # other potential custom behavior - _q_autosuggest_invoke_original_widget "accept-line" + _{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget "accept-line" } # Partially accept the suggestion -_q_autosuggest_partial_accept() { +_{{CLI_BINARY_NAME}}_autosuggest_partial_accept() { local -i retval cursor_loc # Save the contents of the buffer so we can restore later if needed @@ -174,7 +174,7 @@ _q_autosuggest_partial_accept() { BUFFER="$BUFFER$POSTDISPLAY" # Original widget moves the cursor - _q_autosuggest_invoke_original_widget $@ + _{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget $@ retval=$? # Normalize cursor location across vi/emacs modes @@ -199,9 +199,9 @@ _q_autosuggest_partial_accept() { } () { - typeset -ga _Q_AUTOSUGGEST_BUILTIN_ACTIONS + typeset -ga _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BUILTIN_ACTIONS - _Q_AUTOSUGGEST_BUILTIN_ACTIONS=( + _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BUILTIN_ACTIONS=( clear fetch suggest @@ -213,16 +213,16 @@ _q_autosuggest_partial_accept() { ) local action - for action in $_Q_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do - eval "_q_autosuggest_widget_$action() { + for action in $_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do + eval "_{{CLI_BINARY_NAME}}_autosuggest_widget_$action() { local -i retval - _q_autosuggest_highlight_reset + _{{CLI_BINARY_NAME}}_autosuggest_highlight_reset - _q_autosuggest_$action \$@ + _{{CLI_BINARY_NAME}}_autosuggest_$action \$@ retval=\$? - _q_autosuggest_highlight_apply + _{{CLI_BINARY_NAME}}_autosuggest_highlight_apply zle -R @@ -230,7 +230,7 @@ _q_autosuggest_partial_accept() { }" done - for action in $_Q_AUTOSUGGEST_BUILTIN_ACTIONS; do - zle -N autosuggest-$action _q_autosuggest_widget_$action + for action in $_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BUILTIN_ACTIONS; do + zle -N autosuggest-$action _{{CLI_BINARY_NAME}}_autosuggest_widget_$action done } From 2e752c33c5b41a0b745eeec4ffcf3e9a41e858a4 Mon Sep 17 00:00:00 2001 From: kkashilk Date: Wed, 29 Oct 2025 15:50:05 -0700 Subject: [PATCH 3/4] refactor(shell): Use CLI_BINARY_NAME_UNDERSCORE for function names - Add fig_util as build-dependency to access CLI_BINARY_NAME constant - Introduce CLI_BINARY_NAME_UNDERSCORE placeholder for function names (handles hyphens) - Replace _{{CLI_BINARY_NAME}}_ with _{{CLI_BINARY_NAME_UNDERSCORE}}_ in all function names - Keep {{CLI_BINARY_NAME}} for actual binary command usage - Update build.rs to convert hyphens to underscores for function names - Update test to use underscore version for function name checks --- crates/fig_integrations/Cargo.toml | 3 + crates/fig_integrations/build.rs | 9 +-- .../shell/inline_shell_completion/async.zsh | 8 +-- .../shell/inline_shell_completion/bind.zsh | 36 ++++++------ .../shell/inline_shell_completion/fetch.zsh | 4 +- .../inline_shell_completion/highlight.zsh | 4 +- .../shell/inline_shell_completion/start.zsh | 8 +-- .../strategies/completion.zsh | 24 ++++---- .../strategies/history.zsh | 2 +- .../strategies/inline.zsh | 2 +- .../strategies/match_prev_cmd.zsh | 4 +- .../shell/inline_shell_completion/util.zsh | 2 +- .../shell/inline_shell_completion/widgets.zsh | 58 +++++++++---------- crates/fig_integrations/src/shell/mod.rs | 7 ++- 14 files changed, 89 insertions(+), 82 deletions(-) diff --git a/crates/fig_integrations/Cargo.toml b/crates/fig_integrations/Cargo.toml index 9b94383e4..5d5a673ae 100644 --- a/crates/fig_integrations/Cargo.toml +++ b/crates/fig_integrations/Cargo.toml @@ -47,5 +47,8 @@ core-foundation = "0.10.0" plist = "1.7.1" objc.workspace = true +[build-dependencies] +fig_util.workspace = true + [dev-dependencies] tempfile.workspace = true diff --git a/crates/fig_integrations/build.rs b/crates/fig_integrations/build.rs index 30b351def..4f151cbcb 100644 --- a/crates/fig_integrations/build.rs +++ b/crates/fig_integrations/build.rs @@ -1,7 +1,6 @@ -const CODEX_FOLDER: &str = "src/shell/inline_shell_completion"; +use fig_util::CLI_BINARY_NAME; -// Binary name constants for parameterization -const CLI_BINARY_NAME: &str = "q"; +const CODEX_FOLDER: &str = "src/shell/inline_shell_completion"; // The order here is very specific, do no edit without understanding the implications const CODEX_FILES: &[&str] = &[ @@ -36,9 +35,11 @@ fn main() { } // Substitute placeholders with actual binary names - let cli_binary_name_upper = CLI_BINARY_NAME.to_uppercase(); + let cli_binary_name_underscore = CLI_BINARY_NAME.replace('-', "_"); + let cli_binary_name_upper = cli_binary_name_underscore.to_uppercase(); inline_shell_completion = inline_shell_completion .replace("{{CLI_BINARY_NAME}}", CLI_BINARY_NAME) + .replace("{{CLI_BINARY_NAME_UNDERSCORE}}", &cli_binary_name_underscore) .replace("{{CLI_BINARY_NAME_UPPER}}", &cli_binary_name_upper); std::fs::write(out_dir.join("inline_shell_completion.zsh"), inline_shell_completion).unwrap(); diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/async.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/async.zsh index 3b8bd826c..9bb6e8436 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/async.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/async.zsh @@ -3,7 +3,7 @@ # Async # #--------------------------------------------------------------------# -_{{CLI_BINARY_NAME}}_autosuggest_async_request() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_async_request() { zmodload zsh/system 2>/dev/null # For `$sysparams` typeset -g _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ASYNC_FD _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_CHILD_PID @@ -38,7 +38,7 @@ _{{CLI_BINARY_NAME}}_autosuggest_async_request() { # Fetch and print the suggestion local suggestion - _{{CLI_BINARY_NAME}}_autosuggest_fetch_suggestion "$1" + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_fetch_suggestion "$1" echo -nE "$suggestion" ) @@ -51,13 +51,13 @@ _{{CLI_BINARY_NAME}}_autosuggest_async_request() { read _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_CHILD_PID <&$_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ASYNC_FD # When the fd is readable, call the response handler - zle -F "$_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ASYNC_FD" _{{CLI_BINARY_NAME}}_autosuggest_async_response + zle -F "$_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ASYNC_FD" _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_async_response } # Called when new data is ready to be read from the pipe # First arg will be fd ready for reading # Second arg will be passed in case of error -_{{CLI_BINARY_NAME}}_autosuggest_async_response() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_async_response() { emulate -L zsh local suggestion diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/bind.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/bind.zsh index eaccd62d4..0dcfe9a87 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/bind.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/bind.zsh @@ -3,13 +3,13 @@ # Widget Helpers # #--------------------------------------------------------------------# -_{{CLI_BINARY_NAME}}_autosuggest_incr_bind_count() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_incr_bind_count() { typeset -gi bind_count=$((_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BIND_COUNTS[$1]+1)) _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BIND_COUNTS[$1]=$bind_count } # Bind a single widget to an autosuggest widget, saving a reference to the original widget -_{{CLI_BINARY_NAME}}_autosuggest_bind_widget() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_bind_widget() { typeset -gA _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BIND_COUNTS local widget=$1 @@ -21,26 +21,26 @@ _{{CLI_BINARY_NAME}}_autosuggest_bind_widget() { # Save a reference to the original widget case $widgets[$widget] in # Already bound - user:_{{CLI_BINARY_NAME}}_autosuggest_(bound|orig)_*) + user:_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_(bound|orig)_*) bind_count=$((_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BIND_COUNTS[$widget])) ;; # User-defined widget user:*) - _{{CLI_BINARY_NAME}}_autosuggest_incr_bind_count $widget + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_incr_bind_count $widget zle -N $prefix$bind_count-$widget ${widgets[$widget]#*:} ;; # Built-in widget builtin) - _{{CLI_BINARY_NAME}}_autosuggest_incr_bind_count $widget - eval "_{{CLI_BINARY_NAME}}_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }" - zle -N $prefix$bind_count-$widget _{{CLI_BINARY_NAME}}_autosuggest_orig_$widget + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_incr_bind_count $widget + eval "_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }" + zle -N $prefix$bind_count-$widget _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_orig_$widget ;; # Completion widget completion:*) - _{{CLI_BINARY_NAME}}_autosuggest_incr_bind_count $widget + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_incr_bind_count $widget eval "zle -C $prefix$bind_count-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}" ;; esac @@ -51,16 +51,16 @@ _{{CLI_BINARY_NAME}}_autosuggest_bind_widget() { # correctly. $WIDGET cannot be trusted because other plugins call # zle without the `-w` flag (e.g. `zle self-insert` instead of # `zle self-insert -w`). - eval "_{{CLI_BINARY_NAME}}_autosuggest_bound_${bind_count}_${(q)widget}() { - _{{CLI_BINARY_NAME}}_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@ + eval "_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_bound_${bind_count}_${(q)widget}() { + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@ }" # Create the bound widget - zle -N -- $widget _{{CLI_BINARY_NAME}}_autosuggest_bound_${bind_count}_$widget + zle -N -- $widget _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_bound_${bind_count}_$widget } # Map all configured widgets to the right autosuggest widgets -_{{CLI_BINARY_NAME}}_autosuggest_bind_widgets() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_bind_widgets() { emulate -L zsh local widget @@ -77,22 +77,22 @@ _{{CLI_BINARY_NAME}}_autosuggest_bind_widgets() { # Find every widget we might want to bind and bind it appropriately for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do if [[ -n ${{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then - _{{CLI_BINARY_NAME}}_autosuggest_bind_widget $widget clear + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_bind_widget $widget clear elif [[ -n ${{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then - _{{CLI_BINARY_NAME}}_autosuggest_bind_widget $widget accept + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_bind_widget $widget accept elif [[ -n ${{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then - _{{CLI_BINARY_NAME}}_autosuggest_bind_widget $widget execute + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_bind_widget $widget execute elif [[ -n ${{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then - _{{CLI_BINARY_NAME}}_autosuggest_bind_widget $widget partial_accept + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_bind_widget $widget partial_accept else # Assume any unspecified widget might modify the buffer - _{{CLI_BINARY_NAME}}_autosuggest_bind_widget $widget modify + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_bind_widget $widget modify fi done } # Given the name of an original widget and args, invoke it, if it exists -_{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_invoke_original_widget() { # Do nothing unless called with at least one arg (( $# )) || return 0 diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/fetch.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/fetch.zsh index 68aa42b26..790c4fda0 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/fetch.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/fetch.zsh @@ -6,7 +6,7 @@ # from the first strategy to provide one. # -_{{CLI_BINARY_NAME}}_autosuggest_fetch_suggestion() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_fetch_suggestion() { typeset -g suggestion local -a strategies local strategy @@ -16,7 +16,7 @@ _{{CLI_BINARY_NAME}}_autosuggest_fetch_suggestion() { for strategy in $strategies; do # Try to get a suggestion from this strategy - _{{CLI_BINARY_NAME}}_autosuggest_strategy_$strategy "$1" + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_strategy_$strategy "$1" # Ensure the suggestion matches the prefix [[ "$suggestion" != "$1"* ]] && unset suggestion diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/highlight.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/highlight.zsh index 34fe74f42..d7bf66192 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/highlight.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/highlight.zsh @@ -4,7 +4,7 @@ #--------------------------------------------------------------------# # If there was a highlight, remove it -_{{CLI_BINARY_NAME}}_autosuggest_highlight_reset() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_highlight_reset() { typeset -g _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_LAST_HIGHLIGHT if [[ -n "$_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then @@ -14,7 +14,7 @@ _{{CLI_BINARY_NAME}}_autosuggest_highlight_reset() { } # If there's a suggestion, highlight it -_{{CLI_BINARY_NAME}}_autosuggest_highlight_apply() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_highlight_apply() { typeset -g _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_LAST_HIGHLIGHT if (( $#POSTDISPLAY )); then diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/start.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/start.zsh index d3cf349c0..8179626a1 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/start.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/start.zsh @@ -4,7 +4,7 @@ #--------------------------------------------------------------------# # Start the autosuggestion widgets -_{{CLI_BINARY_NAME}}_autosuggest_start() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_start() { # By default we re-bind widgets on every precmd to ensure we wrap other # wrappers. Specifically, highlighting breaks if our widgets are wrapped by # zsh-syntax-highlighting widgets. This also allows modifications to the @@ -12,10 +12,10 @@ _{{CLI_BINARY_NAME}}_autosuggest_start() { # a decent performance hit, so users can set {{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_MANUAL_REBIND # to disable the automatic re-binding. if (( ${+{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_MANUAL_REBIND} )); then - add-zsh-hook -d precmd _{{CLI_BINARY_NAME}}_autosuggest_start + add-zsh-hook -d precmd _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_start fi - _{{CLI_BINARY_NAME}}_autosuggest_bind_widgets + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_bind_widgets } # Mark for auto-loading the functions that we use @@ -30,4 +30,4 @@ if is-at-least 5.0.8; then fi # Start the autosuggestion widgets on the next precmd -add-zsh-hook precmd _{{CLI_BINARY_NAME}}_autosuggest_start +add-zsh-hook precmd _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_start diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/completion.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/completion.zsh index 78891d341..566ae3258 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/completion.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/completion.zsh @@ -5,7 +5,7 @@ # Fetches a suggestion from the completion engine # -_{{CLI_BINARY_NAME}}_autosuggest_capture_postcompletion() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_capture_postcompletion() { # Always insert the first completion into the buffer compstate[insert]=1 @@ -13,12 +13,12 @@ _{{CLI_BINARY_NAME}}_autosuggest_capture_postcompletion() { unset 'compstate[list]' } -_{{CLI_BINARY_NAME}}_autosuggest_capture_completion_widget() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_capture_completion_widget() { # Add a post-completion hook to be called after all completions have been # gathered. The hook can modify compstate to affect what is done with the # gathered completions. local -a +h comppostfuncs - comppostfuncs=(_{{CLI_BINARY_NAME}}_autosuggest_capture_postcompletion) + comppostfuncs=(_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_capture_postcompletion) # Only capture completions at the end of the buffer CURSOR=$#BUFFER @@ -42,9 +42,9 @@ _{{CLI_BINARY_NAME}}_autosuggest_capture_completion_widget() { echo -nE - $'\0'$BUFFER$'\0' } -zle -N autosuggest-capture-completion _{{CLI_BINARY_NAME}}_autosuggest_capture_completion_widget +zle -N autosuggest-capture-completion _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_capture_completion_widget -_{{CLI_BINARY_NAME}}_autosuggest_capture_setup() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_capture_setup() { # There is a bug in zpty module in older zsh versions by which a # zpty that exits will kill all zpty processes that were forked # before it. Here we set up a zsh exit hook to SIGKILL the zpty @@ -69,14 +69,14 @@ _{{CLI_BINARY_NAME}}_autosuggest_capture_setup() { bindkey '^I' autosuggest-capture-completion } -_{{CLI_BINARY_NAME}}_autosuggest_capture_completion_sync() { - _{{CLI_BINARY_NAME}}_autosuggest_capture_setup +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_capture_completion_sync() { + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_capture_setup zle autosuggest-capture-completion } -_{{CLI_BINARY_NAME}}_autosuggest_capture_completion_async() { - _{{CLI_BINARY_NAME}}_autosuggest_capture_setup +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_capture_completion_async() { + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_capture_setup zmodload zsh/parameter 2>/dev/null || return # For `$functions` @@ -93,7 +93,7 @@ _{{CLI_BINARY_NAME}}_autosuggest_capture_completion_async() { vared 1 } -_{{CLI_BINARY_NAME}}_autosuggest_strategy_completion() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_strategy_completion() { # Reset options to defaults and enable LOCAL_OPTIONS emulate -L zsh @@ -114,9 +114,9 @@ _{{CLI_BINARY_NAME}}_autosuggest_strategy_completion() { # Zle will be inactive if we are in async mode if zle; then - zpty ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETIONS_PTY_NAME _{{CLI_BINARY_NAME}}_autosuggest_capture_completion_sync + zpty ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETIONS_PTY_NAME _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_capture_completion_sync else - zpty ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETIONS_PTY_NAME _{{CLI_BINARY_NAME}}_autosuggest_capture_completion_async "\$1" + zpty ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETIONS_PTY_NAME _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_capture_completion_async "\$1" zpty -w ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_COMPLETIONS_PTY_NAME $'\t' fi diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/history.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/history.zsh index 31cc1579d..dcebe2e9d 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/history.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/history.zsh @@ -6,7 +6,7 @@ # prefix. # -_{{CLI_BINARY_NAME}}_autosuggest_strategy_history() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_strategy_history() { # Reset options to defaults and enable LOCAL_OPTIONS emulate -L zsh diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/inline.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/inline.zsh index e031c0d07..d4b94a5ac 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/inline.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/inline.zsh @@ -5,6 +5,6 @@ # Suggests the inline_shell_completion command. # -_{{CLI_BINARY_NAME}}_autosuggest_strategy_inline_shell_completion() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_strategy_inline_shell_completion() { typeset -g suggestion="$(command -v {{CLI_BINARY_NAME}} >/dev/null 2>&1 && {{CLI_BINARY_NAME}} _ inline-shell-completion --buffer "${BUFFER}")" } diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/match_prev_cmd.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/match_prev_cmd.zsh index 6011d7c2b..fb50ea37d 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/strategies/match_prev_cmd.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/strategies/match_prev_cmd.zsh @@ -20,7 +20,7 @@ # preserve the history order such as `HIST_IGNORE_ALL_DUPS` or # `HIST_EXPIRE_DUPS_FIRST`. -_{{CLI_BINARY_NAME}}_autosuggest_strategy_match_prev_cmd() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_strategy_match_prev_cmd() { # Reset options to defaults and enable LOCAL_OPTIONS emulate -L zsh @@ -46,7 +46,7 @@ _{{CLI_BINARY_NAME}}_autosuggest_strategy_match_prev_cmd() { local histkey="${history_match_keys[1]}" # Get the previously executed command - local prev_cmd="$(_{{CLI_BINARY_NAME}}_autosuggest_escape_command "${history[$((HISTCMD-1))]}")" + local prev_cmd="$(_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_escape_command "${history[$((HISTCMD-1))]}")" # Iterate up to the first 200 history event numbers that match $prefix for key in "${(@)history_match_keys[1,200]}"; do diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/util.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/util.zsh index cd8bd211e..3e54517b7 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/util.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/util.zsh @@ -3,7 +3,7 @@ # Utility Functions # #--------------------------------------------------------------------# -_{{CLI_BINARY_NAME}}_autosuggest_escape_command() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_escape_command() { setopt localoptions EXTENDED_GLOB # Escape special chars in the string (requires EXTENDED_GLOB) diff --git a/crates/fig_integrations/src/shell/inline_shell_completion/widgets.zsh b/crates/fig_integrations/src/shell/inline_shell_completion/widgets.zsh index 3c359b4fe..96a2cb6e3 100644 --- a/crates/fig_integrations/src/shell/inline_shell_completion/widgets.zsh +++ b/crates/fig_integrations/src/shell/inline_shell_completion/widgets.zsh @@ -4,39 +4,39 @@ #--------------------------------------------------------------------# # Disable suggestions -_{{CLI_BINARY_NAME}}_autosuggest_disable() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_disable() { typeset -g _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_DISABLED - _{{CLI_BINARY_NAME}}_autosuggest_clear + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_clear } # Enable suggestions -_{{CLI_BINARY_NAME}}_autosuggest_enable() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_enable() { unset _{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_DISABLED if (( $#BUFFER )); then - _{{CLI_BINARY_NAME}}_autosuggest_fetch + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_fetch fi } # Toggle suggestions (enable/disable) -_{{CLI_BINARY_NAME}}_autosuggest_toggle() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_toggle() { if (( ${+_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_DISABLED} )); then - _{{CLI_BINARY_NAME}}_autosuggest_enable + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_enable else - _{{CLI_BINARY_NAME}}_autosuggest_disable + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_disable fi } # Clear the suggestion -_{{CLI_BINARY_NAME}}_autosuggest_clear() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_clear() { # Remove the suggestion unset POSTDISPLAY - _{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget $@ + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_invoke_original_widget $@ } # Modify the buffer and get a new suggestion -_{{CLI_BINARY_NAME}}_autosuggest_modify() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_modify() { local -i retval # Only available in zsh >= 5.4 @@ -50,7 +50,7 @@ _{{CLI_BINARY_NAME}}_autosuggest_modify() { unset POSTDISPLAY # Original widget may modify the buffer - _{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget $@ + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_invoke_original_widget $@ retval=$? emulate -L zsh @@ -75,7 +75,7 @@ _{{CLI_BINARY_NAME}}_autosuggest_modify() { # Get a new suggestion if the buffer is not empty after modification if (( $#BUFFER > 0 )); then if [[ -z "${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= ${{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BUFFER_MAX_SIZE )); then - _{{CLI_BINARY_NAME}}_autosuggest_fetch + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_fetch fi fi @@ -83,18 +83,18 @@ _{{CLI_BINARY_NAME}}_autosuggest_modify() { } # Fetch a new suggestion based on what's currently in the buffer -_{{CLI_BINARY_NAME}}_autosuggest_fetch() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_fetch() { if (( ${+{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_USE_ASYNC} )); then - _{{CLI_BINARY_NAME}}_autosuggest_async_request "$BUFFER" + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_async_request "$BUFFER" else local suggestion - _{{CLI_BINARY_NAME}}_autosuggest_fetch_suggestion "$BUFFER" - _{{CLI_BINARY_NAME}}_autosuggest_suggest "$suggestion" + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_fetch_suggestion "$BUFFER" + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_suggest "$suggestion" fi } # Offer a suggestion -_{{CLI_BINARY_NAME}}_autosuggest_suggest() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_suggest() { emulate -L zsh local suggestion="$1" @@ -107,7 +107,7 @@ _{{CLI_BINARY_NAME}}_autosuggest_suggest() { } # Accept the entire suggestion -_{{CLI_BINARY_NAME}}_autosuggest_accept() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_accept() { local -i retval max_cursor_pos=$#BUFFER # When vicmd keymap is active, the cursor can't move all the way @@ -119,7 +119,7 @@ _{{CLI_BINARY_NAME}}_autosuggest_accept() { # If we're not in a valid state to accept a suggestion, just run the # original widget and bail out if (( $CURSOR != $max_cursor_pos || !$#POSTDISPLAY )); then - _{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget $@ + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_invoke_original_widget $@ return fi @@ -134,7 +134,7 @@ _{{CLI_BINARY_NAME}}_autosuggest_accept() { # Run the original widget before manually moving the cursor so that the # cursor movement doesn't make the widget do something unexpected - _{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget $@ + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_invoke_original_widget $@ retval=$? # Move the cursor to the end of the buffer @@ -148,7 +148,7 @@ _{{CLI_BINARY_NAME}}_autosuggest_accept() { } # Accept the entire suggestion and execute it -_{{CLI_BINARY_NAME}}_autosuggest_execute() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_execute() { # background so we don't block the terminal ({{CLI_BINARY_NAME}} _ inline-shell-completion-accept --buffer "$BUFFER" --suggestion "$POSTDISPLAY" > /dev/null 2>&1 &) @@ -160,11 +160,11 @@ _{{CLI_BINARY_NAME}}_autosuggest_execute() { # Call the original `accept-line` to handle syntax highlighting or # other potential custom behavior - _{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget "accept-line" + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_invoke_original_widget "accept-line" } # Partially accept the suggestion -_{{CLI_BINARY_NAME}}_autosuggest_partial_accept() { +_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_partial_accept() { local -i retval cursor_loc # Save the contents of the buffer so we can restore later if needed @@ -174,7 +174,7 @@ _{{CLI_BINARY_NAME}}_autosuggest_partial_accept() { BUFFER="$BUFFER$POSTDISPLAY" # Original widget moves the cursor - _{{CLI_BINARY_NAME}}_autosuggest_invoke_original_widget $@ + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_invoke_original_widget $@ retval=$? # Normalize cursor location across vi/emacs modes @@ -214,15 +214,15 @@ _{{CLI_BINARY_NAME}}_autosuggest_partial_accept() { local action for action in $_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do - eval "_{{CLI_BINARY_NAME}}_autosuggest_widget_$action() { + eval "_{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_widget_$action() { local -i retval - _{{CLI_BINARY_NAME}}_autosuggest_highlight_reset + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_highlight_reset - _{{CLI_BINARY_NAME}}_autosuggest_$action \$@ + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_$action \$@ retval=\$? - _{{CLI_BINARY_NAME}}_autosuggest_highlight_apply + _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_highlight_apply zle -R @@ -231,6 +231,6 @@ _{{CLI_BINARY_NAME}}_autosuggest_partial_accept() { done for action in $_{{CLI_BINARY_NAME_UPPER}}_AUTOSUGGEST_BUILTIN_ACTIONS; do - zle -N autosuggest-$action _{{CLI_BINARY_NAME}}_autosuggest_widget_$action + zle -N autosuggest-$action _{{CLI_BINARY_NAME_UNDERSCORE}}_autosuggest_widget_$action done } diff --git a/crates/fig_integrations/src/shell/mod.rs b/crates/fig_integrations/src/shell/mod.rs index a51510cc0..18cdf1b4e 100644 --- a/crates/fig_integrations/src/shell/mod.rs +++ b/crates/fig_integrations/src/shell/mod.rs @@ -55,12 +55,15 @@ pub mod inline_shell_completion_plugin { assert!(ZSH_SCRIPT.contains("Copyright")); // Ensure script has _q_autosuggest_strategy_inline_shell_completion() + let cli_binary_name_underscore = CLI_BINARY_NAME.replace('-', "_"); assert!(ZSH_SCRIPT.contains(&format!( - "_{CLI_BINARY_NAME}_autosuggest_strategy_inline_shell_completion()" + "_{cli_binary_name_underscore}_autosuggest_strategy_inline_shell_completion()" ))); // Ensure script adds precmd hook - assert!(ZSH_SCRIPT.contains(&format!("add-zsh-hook precmd _{CLI_BINARY_NAME}_autosuggest_start"))); + assert!(ZSH_SCRIPT.contains(&format!( + "add-zsh-hook precmd _{cli_binary_name_underscore}_autosuggest_start" + ))); } } } From b2ce95b1f836d73e38bc8670635c43681232c535 Mon Sep 17 00:00:00 2001 From: kkashilk Date: Wed, 29 Oct 2025 16:43:19 -0700 Subject: [PATCH 4/4] remove build-dependency to fix test failures --- crates/fig_integrations/Cargo.toml | 3 --- crates/fig_integrations/build.rs | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/fig_integrations/Cargo.toml b/crates/fig_integrations/Cargo.toml index 5d5a673ae..9b94383e4 100644 --- a/crates/fig_integrations/Cargo.toml +++ b/crates/fig_integrations/Cargo.toml @@ -47,8 +47,5 @@ core-foundation = "0.10.0" plist = "1.7.1" objc.workspace = true -[build-dependencies] -fig_util.workspace = true - [dev-dependencies] tempfile.workspace = true diff --git a/crates/fig_integrations/build.rs b/crates/fig_integrations/build.rs index 4f151cbcb..eb5fec3ab 100644 --- a/crates/fig_integrations/build.rs +++ b/crates/fig_integrations/build.rs @@ -1,5 +1,4 @@ -use fig_util::CLI_BINARY_NAME; - +const CLI_BINARY_NAME: &str = "q"; const CODEX_FOLDER: &str = "src/shell/inline_shell_completion"; // The order here is very specific, do no edit without understanding the implications