Skip to content

Commit c56cf5e

Browse files
committed
Added a check for interactivity before shell completion initialization
1 parent ecd7155 commit c56cf5e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/client/opamState.ml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,14 @@ let init_file = function
692692
| `csh -> init_csh
693693
| `zsh -> init_zsh
694694

695-
let source t f =
695+
let source t ?(interactive_only=false) f =
696696
let file f = OpamFilename.to_string (OpamPath.init t.root // f) in
697-
Printf.sprintf ". %s > /dev/null 2> /dev/null || true\n" (file f)
697+
let s =
698+
Printf.sprintf ". %s > /dev/null 2> /dev/null || true\n" (file f)
699+
in
700+
if interactive_only then
701+
Printf.sprintf "if tty -s >/dev/null 2>&1; then\n %sfi\n" s
702+
else s
698703

699704
(* Return the contents of a fully qualified variable *)
700705
let contents_of_variable t v =
@@ -961,12 +966,12 @@ let init_script t ~switch_eval ~complete (variables_sh, switch_eval_sh, complete
961966
Some (source t variables_sh) in
962967
let switch_eval =
963968
if switch_eval then
964-
Some (source t switch_eval_sh)
969+
Some (source t ~interactive_only:true switch_eval_sh)
965970
else
966971
None in
967972
let complete =
968973
if complete then
969-
Some (source t complete_sh)
974+
Some (source t ~interactive_only:true complete_sh)
970975
else
971976
None in
972977
let buf = Buffer.create 128 in
@@ -1096,7 +1101,7 @@ let update_dot_profile t dot_profile shell =
10961101
Printf.sprintf
10971102
"%s\n\n\
10981103
# OPAM configuration\n\
1099-
%s\n"
1104+
%s"
11001105
(OpamMisc.strip body) (source t init_file) in
11011106
OpamFilename.write dot_profile body
11021107

0 commit comments

Comments
 (0)