Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ pub fn shell_wrapper_snippet(shell: ShellKind, binary_name: &str) -> String {
r#"function {binary_name}
if test (count $argv) -gt 0; and test $argv[1] = go -o $argv[1] = g
set -l target (command {binary_name} go $argv[2..-1] --print-path)
set -l go_status $status
if test $go_status -ne 0
return $go_status
end
if test -n "$target"
cd $target
end
Expand All @@ -118,7 +122,7 @@ end"#
r#"{binary_name}() {{
if [ "$1" = "go" ] || [ "$1" = "g" ]; then
local dir
dir=$(command {binary_name} go "${{@:2}}" --print-path)
dir=$(command {binary_name} go "${{@:2}}" --print-path) || return $?
if [ -n "$dir" ]; then
cd "$dir"
fi
Expand Down Expand Up @@ -287,8 +291,14 @@ mod tests {

#[test]
fn wrapper_generation_matches_shell() {
assert!(shell_wrapper_snippet(ShellKind::Zsh, "qr").contains(r#"dir=$(command qr go"#));
assert!(shell_wrapper_snippet(ShellKind::Fish, "qr").contains("function qr"));
let zsh = shell_wrapper_snippet(ShellKind::Zsh, "qr");
assert!(zsh.contains(r#"dir=$(command qr go"#));
assert!(zsh.contains("|| return $?"));

let fish = shell_wrapper_snippet(ShellKind::Fish, "qr");
assert!(fish.contains("function qr"));
assert!(fish.contains("set -l go_status $status"));
assert!(fish.contains("return $go_status"));
}

#[test]
Expand Down
Loading