Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat: Suggest `source` command for current shell

Maximilian Roosfcd19de1e8c3
diff --git a/src/main.rs b/src/main.rs
index 24c2a6b43..6dde5587f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -268,9 +268,26 @@ fn main() {
"{SUCCESS_EMOJI} {green}Configured {changes_count} shell{plural}{green:#}"
);
println!();
- println!(
- "{HINT_EMOJI} {HINT}Restart your shell or run: source <config-file>{HINT:#}"
- );
+
+ // Find the config file for the current shell
+ let current_shell = std::env::var("SHELL")
+ .ok()
+ .and_then(|s| s.rsplit('/').next().map(String::from));
+
+ let current_shell_path = current_shell.as_ref().and_then(|shell_name| {
+ scan_result
+ .configured
+ .iter()
+ .filter(|r| !matches!(r.action, ConfigAction::AlreadyExists))
+ .find(|r| r.shell.to_string().eq_ignore_ascii_case(shell_name))
+ .map(|r| format_path_for_display(&r.path))
+ });
+
+ if let Some(path) = current_shell_path {
+ println!(
+ "{HINT_EMOJI} {HINT}Restart your shell or run: source {path}{HINT:#}"
+ );
+ }
} else {
println!(
"{SUCCESS_EMOJI} {green}All shells already configured{green:#}"
diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rs
index e366f6807..b4a3fe586 100644
--- a/tests/integration_tests/configure_shell.rs
+++ b/tests/integration_tests/configure_shell.rs
@@ -18,6 +18,7 @@ fn test_configure_shell_with_yes() {
let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
.arg("shell")
.arg("install")
@@ -35,7 +36,7 @@ fn test_configure_shell_with_yes() {
βœ… Configured 1 shell
- πŸ’‘ Restart your shell or run: source <config-file>
+ πŸ’‘ Restart your shell or run: source ~/.zshrc
----- stderr -----
"#);
@@ -61,6 +62,7 @@ fn test_configure_shell_specific_shell() {
let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
.arg("shell")
.arg("install")
@@ -77,7 +79,7 @@ fn test_configure_shell_specific_shell() {
βœ… Configured 1 shell
- πŸ’‘ Restart your shell or run: source <config-file>
+ πŸ’‘ Restart your shell or run: source ~/.zshrc
----- stderr -----
"#);
@@ -107,6 +109,7 @@ fn test_configure_shell_already_exists() {
let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
.arg("shell")
.arg("install")
@@ -142,6 +145,7 @@ fn test_configure_shell_fish() {
let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/fish");
cmd.arg("config")
.arg("shell")
.arg("install")
@@ -158,7 +162,7 @@ fn test_configure_shell_fish() {
βœ… Configured 1 shell
- πŸ’‘ Restart your shell or run: source <config-file>
+ πŸ’‘ Restart your shell or run: source ~/.config/fish/conf.d/wt.fish
----- stderr -----
");
@@ -187,6 +191,7 @@ fn test_configure_shell_no_files() {
let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
.arg("shell")
.arg("install")
@@ -224,6 +229,7 @@ fn test_configure_shell_multiple_configs() {
let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
.arg("shell")
.arg("install")
@@ -242,7 +248,7 @@ fn test_configure_shell_multiple_configs() {
βœ… Configured 2 shells
- πŸ’‘ Restart your shell or run: source <config-file>
+ πŸ’‘ Restart your shell or run: source ~/.zshrc
----- stderr -----
"#);
@@ -285,6 +291,7 @@ fn test_configure_shell_mixed_states() {
let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("SHELL", "/bin/zsh");
cmd.arg("config")
.arg("shell")
.arg("install")
@@ -303,7 +310,7 @@ fn test_configure_shell_mixed_states() {
βœ… Configured 1 shell
- πŸ’‘ Restart your shell or run: source <config-file>
+ πŸ’‘ Restart your shell or run: source ~/.zshrc
----- stderr -----
"#);