Skip to content

Commit

Permalink
Fish integration: make sure we're not in login mode before sourcing f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
ElectreAAS committed Jan 23, 2024
1 parent a358d94 commit 0254eee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/state/opamEnv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -873,12 +873,15 @@ let env_hook_script shell =
(env_hook_script_base shell)

let source root shell f =
let fname = OpamFilename.to_string (OpamPath.init root // f) in
let fname = OpamFilename.prettify (OpamPath.init root // f) in
match shell with
| SH_csh ->
Printf.sprintf "if ( -f %s ) source %s >& /dev/null\n" fname fname
| SH_fish ->
Printf.sprintf "source %s > /dev/null 2> /dev/null; or true\n" fname
if f = init_file shell then
Printf.sprintf "if not status is-login; and test -r %s\n source %s\nend\n" fname fname
else
Printf.sprintf "source %s\n" fname
| SH_sh | SH_bash ->
Printf.sprintf "test -r %s && . %s > /dev/null 2> /dev/null || true\n"
fname fname
Expand Down Expand Up @@ -911,7 +914,7 @@ let if_interactive_script shell t e =
| SH_csh ->
Printf.sprintf "if ( $?prompt ) then\n %s%sendif\n" t @@ ielse e
| SH_fish ->
Printf.sprintf "if isatty\n %s%send\n" t @@ ielse e
Printf.sprintf "if status is-interactive\n %s%send\n" t @@ ielse e
| SH_cmd ->
Printf.sprintf "echo %%cmdcmdline%% | find /i \"%%~0\" >nul\nif errorlevel 1 (\n%s%s)\n" t @@ ielse_cmd e
| SH_pwsh _ ->
Expand Down Expand Up @@ -1174,7 +1177,8 @@ let setup
\ Otherwise, every time"
(OpamConsole.colorise `bold (string_of_shell shell))
(OpamConsole.colorise `cyan @@ OpamFilename.prettify dot_profile)
(OpamConsole.colorise `bold @@ source root shell (init_file shell));
(OpamConsole.colorise `bold @@ String.concat "\n " @@
String.split_on_char '\n' (source root shell (init_file shell)));
| None ->
OpamConsole.msg "When"
end;
Expand Down
4 changes: 2 additions & 2 deletions src/state/shellscripts/env_hook.fish
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function __opam_env_export_eval --on-event fish_prompt;
eval (opam env --shell=fish --readonly 2> /dev/null);
function __opam_env_export_eval --on-event fish_prompt
eval (opam env --shell=fish --readonly 2> /dev/null)
end

0 comments on commit 0254eee

Please sign in to comment.