Skip to content

Commit

Permalink
activate: use full path to rtx (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Dec 14, 2023
1 parent e8ccf67 commit ac2d364
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 48 deletions.
7 changes: 4 additions & 3 deletions src/shell/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct Bash {}
impl Shell for Bash {
fn activate(&self, exe: &Path, status: bool) -> String {
let dir = exe.parent().unwrap();
let exe = exe.to_string_lossy();
let status = if status { " --status" } else { "" };
let mut out = String::new();
if is_dir_not_in_nix(dir) && !is_dir_in_path(dir) {
Expand All @@ -21,7 +22,7 @@ impl Shell for Bash {
local command
command="${{1:-}}"
if [ "$#" = 0 ]; then
command rtx
command {exe}
return
fi
shift
Expand All @@ -30,12 +31,12 @@ impl Shell for Bash {
deactivate|s|shell)
# if argv doesn't contains -h,--help
if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]]; then
eval "$(command rtx "$command" "$@")"
eval "$(command {exe} "$command" "$@")"
return $?
fi
;;
esac
command rtx "$command" "$@"
command {exe} "$command" "$@"
}}
_rtx_hook() {{
Expand Down
19 changes: 10 additions & 9 deletions src/shell/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct Fish {}
impl Shell for Fish {
fn activate(&self, exe: &Path, status: bool) -> String {
let dir = exe.parent().unwrap();
let exe = exe.to_string_lossy();
let status = if status { " --status" } else { "" };
let description = "'Update rtx environment when changing directories'";
let mut out = String::new();
Expand All @@ -24,42 +25,42 @@ impl Shell for Fish {
function rtx
if test (count $argv) -eq 0
command rtx
command {exe}
return
end
set command $argv[1]
set -e argv[1]
if contains -- --help $argv
command rtx "$command" $argv
command {exe} "$command" $argv
return $status
end
switch "$command"
case deactivate s shell
# if help is requested, don't eval
if contains -- -h $argv
command rtx "$command" $argv
command {exe} "$command" $argv
else if contains -- --help $argv
command rtx "$command" $argv
command {exe} "$command" $argv
else
source (command rtx "$command" $argv |psub)
source (command {exe} "$command" $argv |psub)
end
case '*'
command rtx "$command" $argv
command {exe} "$command" $argv
end
end
function __rtx_env_eval --on-event fish_prompt --description {description};
rtx hook-env{status} -s fish | source;
{exe} hook-env{status} -s fish | source;
if test "$rtx_fish_mode" != "disable_arrow";
function __rtx_cd_hook --on-variable PWD --description {description};
if test "$rtx_fish_mode" = "eval_after_arrow";
set -g __rtx_env_again 0;
else;
rtx hook-env{status} -s fish | source;
{exe} hook-env{status} -s fish | source;
end;
end;
end;
Expand All @@ -68,7 +69,7 @@ impl Shell for Fish {
function __rtx_env_eval_2 --on-event fish_preexec --description {description};
if set -q __rtx_env_again;
set -e __rtx_env_again;
rtx hook-env{status} -s fish | source;
{exe} hook-env{status} -s fish | source;
echo;
end;
Expand Down
6 changes: 3 additions & 3 deletions src/shell/snapshots/rtx__shell__bash__tests__hook_init.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ rtx() {
local command
command="${1:-}"
if [ "$#" = 0 ]; then
command rtx
command /some/dir/rtx
return
fi
shift
Expand All @@ -19,12 +19,12 @@ rtx() {
deactivate|s|shell)
# if argv doesn't contains -h,--help
if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]]; then
eval "$(command rtx "$command" "$@")"
eval "$(command /some/dir/rtx "$command" "$@")"
return $?
fi
;;
esac
command rtx "$command" "$@"
command /some/dir/rtx "$command" "$@"
}

_rtx_hook() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rtx() {
local command
command="${1:-}"
if [ "$#" = 0 ]; then
command rtx
command /nix/store/rtx
return
fi
shift
Expand All @@ -18,12 +18,12 @@ rtx() {
deactivate|s|shell)
# if argv doesn't contains -h,--help
if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]]; then
eval "$(command rtx "$command" "$@")"
eval "$(command /nix/store/rtx "$command" "$@")"
return $?
fi
;;
esac
command rtx "$command" "$@"
command /nix/store/rtx "$command" "$@"
}

_rtx_hook() {
Expand Down
18 changes: 9 additions & 9 deletions src/shell/snapshots/rtx__shell__fish__tests__hook_init.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@ set -gx __RTX_ORIG_PATH $PATH

function rtx
if test (count $argv) -eq 0
command rtx
command /some/dir/rtx
return
end

set command $argv[1]
set -e argv[1]

if contains -- --help $argv
command rtx "$command" $argv
command /some/dir/rtx "$command" $argv
return $status
end

switch "$command"
case deactivate s shell
# if help is requested, don't eval
if contains -- -h $argv
command rtx "$command" $argv
command /some/dir/rtx "$command" $argv
else if contains -- --help $argv
command rtx "$command" $argv
command /some/dir/rtx "$command" $argv
else
source (command rtx "$command" $argv |psub)
source (command /some/dir/rtx "$command" $argv |psub)
end
case '*'
command rtx "$command" $argv
command /some/dir/rtx "$command" $argv
end
end

function __rtx_env_eval --on-event fish_prompt --description 'Update rtx environment when changing directories';
rtx hook-env --status -s fish | source;
/some/dir/rtx hook-env --status -s fish | source;

if test "$rtx_fish_mode" != "disable_arrow";
function __rtx_cd_hook --on-variable PWD --description 'Update rtx environment when changing directories';
if test "$rtx_fish_mode" = "eval_after_arrow";
set -g __rtx_env_again 0;
else;
rtx hook-env --status -s fish | source;
/some/dir/rtx hook-env --status -s fish | source;
end;
end;
end;
Expand All @@ -52,7 +52,7 @@ end;
function __rtx_env_eval_2 --on-event fish_preexec --description 'Update rtx environment when changing directories';
if set -q __rtx_env_again;
set -e __rtx_env_again;
rtx hook-env --status -s fish | source;
/some/dir/rtx hook-env --status -s fish | source;
echo;
end;

Expand Down
18 changes: 9 additions & 9 deletions src/shell/snapshots/rtx__shell__fish__tests__hook_init_nix.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@ set -gx __RTX_ORIG_PATH $PATH

function rtx
if test (count $argv) -eq 0
command rtx
command /nix/store/rtx
return
end

set command $argv[1]
set -e argv[1]

if contains -- --help $argv
command rtx "$command" $argv
command /nix/store/rtx "$command" $argv
return $status
end

switch "$command"
case deactivate s shell
# if help is requested, don't eval
if contains -- -h $argv
command rtx "$command" $argv
command /nix/store/rtx "$command" $argv
else if contains -- --help $argv
command rtx "$command" $argv
command /nix/store/rtx "$command" $argv
else
source (command rtx "$command" $argv |psub)
source (command /nix/store/rtx "$command" $argv |psub)
end
case '*'
command rtx "$command" $argv
command /nix/store/rtx "$command" $argv
end
end

function __rtx_env_eval --on-event fish_prompt --description 'Update rtx environment when changing directories';
rtx hook-env --status -s fish | source;
/nix/store/rtx hook-env --status -s fish | source;

if test "$rtx_fish_mode" != "disable_arrow";
function __rtx_cd_hook --on-variable PWD --description 'Update rtx environment when changing directories';
if test "$rtx_fish_mode" = "eval_after_arrow";
set -g __rtx_env_again 0;
else;
rtx hook-env --status -s fish | source;
/nix/store/rtx hook-env --status -s fish | source;
end;
end;
end;
Expand All @@ -51,7 +51,7 @@ end;
function __rtx_env_eval_2 --on-event fish_preexec --description 'Update rtx environment when changing directories';
if set -q __rtx_env_again;
set -e __rtx_env_again;
rtx hook-env --status -s fish | source;
/nix/store/rtx hook-env --status -s fish | source;
echo;
end;

Expand Down
8 changes: 4 additions & 4 deletions src/shell/snapshots/rtx__shell__zsh__tests__hook_init.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ rtx() {
local command
command="${1:-}"
if [ "$#" = 0 ]; then
command rtx
command /some/dir/rtx
return
fi
shift
Expand All @@ -19,16 +19,16 @@ rtx() {
deactivate|s|shell)
# if argv doesn't contains -h,--help
if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]]; then
eval "$(command rtx "$command" "$@")"
eval "$(command /some/dir/rtx "$command" "$@")"
return $?
fi
;;
esac
command rtx "$command" "$@"
command /some/dir/rtx "$command" "$@"
}

_rtx_hook() {
eval "$(rtx hook-env --status -s zsh)";
eval "$(/some/dir/rtx hook-env --status -s zsh)";
}
typeset -ag precmd_functions;
if [[ -z "${precmd_functions[(r)_rtx_hook]+1}" ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rtx() {
local command
command="${1:-}"
if [ "$#" = 0 ]; then
command rtx
command /nix/store/rtx
return
fi
shift
Expand All @@ -18,16 +18,16 @@ rtx() {
deactivate|s|shell)
# if argv doesn't contains -h,--help
if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]]; then
eval "$(command rtx "$command" "$@")"
eval "$(command /nix/store/rtx "$command" "$@")"
return $?
fi
;;
esac
command rtx "$command" "$@"
command /nix/store/rtx "$command" "$@"
}

_rtx_hook() {
eval "$(rtx hook-env --status -s zsh)";
eval "$(/nix/store/rtx hook-env --status -s zsh)";
}
typeset -ag precmd_functions;
if [[ -z "${precmd_functions[(r)_rtx_hook]+1}" ]]; then
Expand Down
9 changes: 5 additions & 4 deletions src/shell/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Zsh {}
impl Shell for Zsh {
fn activate(&self, exe: &Path, status: bool) -> String {
let dir = exe.parent().unwrap();
let exe = exe.to_string_lossy();
let status = if status { " --status" } else { "" };
let mut out = String::new();

Expand All @@ -25,7 +26,7 @@ impl Shell for Zsh {
local command
command="${{1:-}}"
if [ "$#" = 0 ]; then
command rtx
command {exe}
return
fi
shift
Expand All @@ -34,16 +35,16 @@ impl Shell for Zsh {
deactivate|s|shell)
# if argv doesn't contains -h,--help
if [[ ! " $@ " =~ " --help " ]] && [[ ! " $@ " =~ " -h " ]]; then
eval "$(command rtx "$command" "$@")"
eval "$(command {exe} "$command" "$@")"
return $?
fi
;;
esac
command rtx "$command" "$@"
command {exe} "$command" "$@"
}}
_rtx_hook() {{
eval "$(rtx hook-env{status} -s zsh)";
eval "$({exe} hook-env{status} -s zsh)";
}}
typeset -ag precmd_functions;
if [[ -z "${{precmd_functions[(r)_rtx_hook]+1}}" ]]; then
Expand Down

0 comments on commit ac2d364

Please sign in to comment.