Skip to content

Commit c1f9063

Browse files
committed
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.
1 parent 50e57ac commit c1f9063

File tree

9 files changed

+39
-34
lines changed

9 files changed

+39
-34
lines changed

crates/fig_integrations/src/shell/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use fig_os_shim::Env;
1212
use fig_util::{
1313
CLI_BINARY_NAME,
1414
PRODUCT_NAME,
15+
PTY_BINARY_NAME,
1516
Shell,
1617
directories,
1718
};
@@ -97,7 +98,7 @@ pub trait ShellExt {
9798
fn get_shell_integrations(&self, env: &Env) -> Result<Vec<Box<dyn ShellIntegration>>>;
9899
/// Script integrations are installed into ~/.fig/shell
99100
fn get_script_integrations(&self) -> Result<Vec<ShellScriptShellIntegration>>;
100-
fn get_fig_integration_source(&self, when: &When) -> &'static str;
101+
fn get_fig_integration_source(&self, when: &When) -> String;
101102
}
102103

103104
impl ShellExt for Shell {
@@ -186,8 +187,8 @@ impl ShellExt for Shell {
186187
Ok(integrations)
187188
}
188189

189-
fn get_fig_integration_source(&self, when: &When) -> &'static str {
190-
match (self, when) {
190+
fn get_fig_integration_source(&self, when: &When) -> String {
191+
let script = match (self, when) {
191192
(Shell::Fish, When::Pre) => include_str!("scripts/pre.fish"),
192193
(Shell::Fish, When::Post) => include_str!("scripts/post.fish"),
193194
(Shell::Zsh, When::Pre) => include_str!("scripts/pre.sh"),
@@ -216,7 +217,11 @@ impl ShellExt for Shell {
216217
},
217218
(Shell::Nu, When::Pre) => include_str!("scripts/pre.nu"),
218219
(Shell::Nu, When::Post) => include_str!("scripts/post.nu"),
219-
}
220+
};
221+
222+
script
223+
.replace("{{CLI_BINARY_NAME}}", CLI_BINARY_NAME)
224+
.replace("{{PTY_BINARY_NAME}}", PTY_BINARY_NAME)
220225
}
221226
}
222227

@@ -814,7 +819,7 @@ mod test {
814819
}
815820

816821
fn check_script(shell: Shell, when: When) {
817-
run_shellcheck(shell.get_fig_integration_source(&when).to_owned());
822+
run_shellcheck(shell.get_fig_integration_source(&when));
818823
}
819824

820825
#[test]

crates/fig_integrations/src/shell/scripts/post.bash

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Q_LAST_PS2="$PS2"
1717
Q_LAST_PS3="$PS3"
1818

1919
if [[ -z "${Q_SHELL:-}" ]]; then
20-
Q_SHELL=$(q _ get-shell)
20+
Q_SHELL=$({{CLI_BINARY_NAME}} _ get-shell)
2121
fi
2222

2323
# Construct Operating System Command.
@@ -68,8 +68,8 @@ function __fig_pre_prompt () {
6868
fig_osc "Log=%s" "${Q_LOG_LEVEL}"
6969
fig_osc "User=%s" "${USER:-root}"
7070

71-
if command -v q >/dev/null 2>&1; then
72-
(command q _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1
71+
if command -v {{CLI_BINARY_NAME}} >/dev/null 2>&1; then
72+
(command {{CLI_BINARY_NAME}} _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1
7373
fi
7474

7575
# Work around bug in CentOS 7.2 where preexec doesn't run if you press ^C
@@ -180,4 +180,4 @@ fi
180180

181181
fi
182182

183-
(command q _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1
183+
(command {{CLI_BINARY_NAME}} _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1

crates/fig_integrations/src/shell/scripts/post.fish

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set --export TTY
66

77
set --export SHELL_PID $fish_pid
88

9-
set --query Q_SHELL; or set Q_SHELL (q _ get-shell)
9+
set --query Q_SHELL; or set Q_SHELL ({{CLI_BINARY_NAME}} _ get-shell)
1010

1111
function fig_osc
1212
builtin printf "\033]697;$argv[1]\007" $argv[2..-1]
@@ -98,8 +98,8 @@ function fig_precmd --on-event fish_prompt
9898

9999
set fig_has_set_prompt 1
100100

101-
if command -v q &>/dev/null
102-
begin; command q _ pre-cmd --alias (alias) &> /dev/null &; end
101+
if command -v {{CLI_BINARY_NAME}} &>/dev/null
102+
begin; command {{CLI_BINARY_NAME}} _ pre-cmd --alias (alias) &> /dev/null &; end
103103
end
104104
end
105105

@@ -109,4 +109,4 @@ if test -n "$PROCESS_LAUNCHED_BY_Q"
109109
fig_osc DoneSourcing
110110
end
111111

112-
begin; command q _ pre-cmd --alias (alias) &> /dev/null &; end
112+
begin; command {{CLI_BINARY_NAME}} _ pre-cmd --alias (alias) &> /dev/null &; end

crates/fig_integrations/src/shell/scripts/post.nu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def pathadd [path: string] {
77
}
88

99
let-env PATH = pathadd $"($env.HOME)/.local/bin"
10-
let-env Q_SHELL = (^q _ get-shell)
10+
let-env Q_SHELL = (^{{CLI_BINARY_NAME}} _ get-shell)
1111

1212
let-env PATH = $env.PATH
1313

@@ -143,7 +143,7 @@ def-env fig_pre_prompt_hook [] {
143143
# }
144144

145145
if (which fig | length) >= 1 {
146-
let result = (q _ pre-cmd | complete)
146+
let result = ({{CLI_BINARY_NAME}} _ pre-cmd | complete)
147147
if $result.stdout == "EXEC_NEW_SHELL" {
148148
let-env Q_DOTFILES_SOURCED = $nothing
149149
exec nu
@@ -208,4 +208,4 @@ if "PROCESS_LAUNCHED_BY_Q" in $env {
208208
print_fig_osc "DoneSourcing"
209209
}
210210

211-
(^q _ pre-cmd | complete | ignore)
211+
(^{{CLI_BINARY_NAME}} _ pre-cmd | complete | ignore)

crates/fig_integrations/src/shell/scripts/post.zsh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export TTY
1313
export SHELL_PID="$$"
1414

1515
if [[ -z "${Q_SHELL:-}" ]]; then
16-
Q_SHELL=$(q _ get-shell)
16+
Q_SHELL=$({{CLI_BINARY_NAME}} _ get-shell)
1717
fi
1818

1919
# shellcheck disable=SC2059
@@ -165,8 +165,8 @@ fig_precmd() {
165165

166166
Q_HAS_SET_PROMPT=1
167167

168-
if command -v q >/dev/null 2>&1; then
169-
(command q _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1
168+
if command -v {{CLI_BINARY_NAME}} >/dev/null 2>&1; then
169+
(command {{CLI_BINARY_NAME}} _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1
170170
fi
171171
}
172172

@@ -190,4 +190,4 @@ fi
190190

191191
fi
192192

193-
(command q _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1
193+
(command {{CLI_BINARY_NAME}} _ pre-cmd --alias "$(\alias)" > /dev/null 2>&1 &) >/dev/null 2>&1

crates/fig_integrations/src/shell/scripts/pre.fish

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@ end
1616

1717
if test -z "$SHOULD_QTERM_LAUNCH"
1818
# 0 = Yes, 1 = No, 2 = Fallback to Q_TERM
19-
q _ should-figterm-launch 1>/dev/null 2>&1
19+
{{CLI_BINARY_NAME}} _ should-figterm-launch 1>/dev/null 2>&1
2020
set SHOULD_QTERM_LAUNCH $status
2121
end
2222

2323
if test -t 1
2424
and test -z "$PROCESS_LAUNCHED_BY_Q"
25-
and command -v qterm 1>/dev/null 2>/dev/null
25+
and command -v {{PTY_BINARY_NAME}} 1>/dev/null 2>/dev/null
2626
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" \) \) \)
2727

2828
if test -z "$Q_SHELL"
29-
set Q_SHELL (q _ get-shell)
29+
set Q_SHELL ({{CLI_BINARY_NAME}} _ get-shell)
3030
end
3131
set Q_IS_LOGIN_SHELL 0
3232
if status --is-login
3333
set Q_IS_LOGIN_SHELL 1
3434
end
3535

36-
# Do not launch qterm in non-interactive shells (like VSCode Tasks)
36+
# Do not launch {{PTY_BINARY_NAME}} in non-interactive shells (like VSCode Tasks)
3737
if status --is-interactive
38-
set Q_TERM_NAME (command basename "$Q_SHELL")" (qterm)"
38+
set Q_TERM_NAME (command basename "$Q_SHELL")" ({{PTY_BINARY_NAME}})"
3939
if not set -q Q_TERM_PATH
4040
if test -x "$HOME/.local/bin/$Q_TERM_NAME"
4141
set Q_TERM_PATH "$HOME/.local/bin/$Q_TERM_NAME"
4242
else
43-
set Q_TERM_PATH (command -v qterm || echo "$HOME/.local/bin/qterm")
43+
set Q_TERM_PATH (command -v {{PTY_BINARY_NAME}} || echo "$HOME/.local/bin/{{PTY_BINARY_NAME}}")
4444
end
4545
end
4646

crates/fig_integrations/src/shell/scripts/pre.nu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if "Q_SET_PARENT_CHECK" not-in $env {
2626
}
2727

2828

29-
let result = (^q _ should-figterm-launch | complete)
29+
let result = (^{{CLI_BINARY_NAME}} _ should-figterm-launch | complete)
3030
let-env SHOULD_QTERM_LAUNCH = $result.exit_code
3131

3232
let should_launch = (
@@ -36,7 +36,7 @@ let should_launch = (
3636
)
3737

3838
if $should_launch {
39-
let Q_SHELL = (q _ get-shell | complete).stdout
39+
let Q_SHELL = ({{CLI_BINARY_NAME}} _ get-shell | complete).stdout
4040

4141
let fig_term_name = "nu (figterm)"
4242
let figterm_path = if ([$env.HOME ".fig" "bin" $fig_term_name] | path join | path exists) {

crates/fig_integrations/src/shell/scripts/pre.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fi
2424

2525
# 0 = Yes, 1 = No, 2 = Fallback to Q_TERM
2626
if [ -z "${SHOULD_QTERM_LAUNCH:-}" ]; then
27-
q _ should-figterm-launch 1>/dev/null 2>&1
27+
{{CLI_BINARY_NAME}} _ should-figterm-launch 1>/dev/null 2>&1
2828
SHOULD_QTERM_LAUNCH=$?
2929
fi
3030

@@ -33,12 +33,12 @@ fi
3333
# It is not necessary in Fish.
3434
if [[ -t 1 ]] \
3535
&& [[ -z "${PROCESS_LAUNCHED_BY_Q:-}" ]] \
36-
&& command -v qterm 1>/dev/null 2>&1 \
36+
&& command -v {{PTY_BINARY_NAME}} 1>/dev/null 2>&1 \
3737
&& [[ ("${SHOULD_QTERM_LAUNCH}" -eq 0) || (("${SHOULD_QTERM_LAUNCH}" -eq 2) && (-z "${Q_TERM:-}" || (-z "${Q_TERM_TMUX:-}" && -n "${TMUX:-}"))) ]]
3838
then
3939
# Pty module sets Q_TERM or Q_TERM_TMUX to avoid running twice.
4040
if [ -z "${Q_SHELL:-}" ]; then
41-
Q_SHELL=$(q _ get-shell)
41+
Q_SHELL=$({{CLI_BINARY_NAME}} _ get-shell)
4242
fi
4343
Q_IS_LOGIN_SHELL="${Q_IS_LOGIN_SHELL:='0'}"
4444

@@ -50,12 +50,12 @@ then
5050

5151
# Do not launch figterm in non-interactive shells (like VSCode Tasks)
5252
if [[ $- == *i* ]]; then
53-
Q_TERM_NAME="$(basename "${Q_SHELL}") (qterm)"
53+
Q_TERM_NAME="$(basename "${Q_SHELL}") ({{PTY_BINARY_NAME}})"
5454
if [[ -z "${Q_TERM_PATH:-}" ]]; then
5555
if [[ -x "${HOME}/.local/bin/${Q_TERM_NAME}" ]]; then
5656
Q_TERM_PATH="${HOME}/.local/bin/${Q_TERM_NAME}"
5757
else
58-
Q_TERM_PATH="$(command -v qterm || echo "${HOME}/.local/bin/qterm")"
58+
Q_TERM_PATH="$(command -v {{PTY_BINARY_NAME}} || echo "${HOME}/.local/bin/{{PTY_BINARY_NAME}}")"
5959
fi
6060
fi
6161

crates/q_cli/src/cli/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ async fn shell_init(shell: &Shell, when: &When, rcfile: &Option<String>) -> Resu
204204
}
205205

206206
let shell_integration_source = shell.get_fig_integration_source(when);
207-
to_source.push(shell_integration_source.into());
207+
to_source.push(shell_integration_source);
208208

209209
if when == &When::Pre && is_jetbrains_terminal {
210210
// Manually call JetBrains shell integration after exec-ing to figterm.

0 commit comments

Comments
 (0)