[Pkg-ocaml-maint-commits] [opam] 01/02: Fix integration with fish shell (Closes: #805270)

Mehdi Dogguy mehdi at moszumanska.debian.org
Tue Dec 22 11:23:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

mehdi pushed a commit to branch master
in repository opam.

commit ec7ecc706ff9fdff3afbf53c1ccb0c68eb5338ad
Author: Mehdi Dogguy <mehdi at debian.org>
Date:   Tue Dec 22 11:54:07 2015 +0100

    Fix integration with fish shell (Closes: #805270)
---
 debian/changelog                                   |  6 ++
 .../0002-Fix-integration-with-fish-shell.patch     | 81 ++++++++++++++++++++++
 debian/patches/series                              |  1 +
 3 files changed, 88 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index f9f26d7..5ded3ff 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+opam (1.2.2-4) UNRELEASED; urgency=medium
+
+  * Fix integration with fish shell (Closes: #805270)
+
+ -- Mehdi Dogguy <mehdi at debian.org>  Tue, 22 Dec 2015 11:52:50 +0100
+
 opam (1.2.2-3) unstable; urgency=medium
 
   * Port to Dose3 4.0.1 (Closes: #797451)
diff --git a/debian/patches/0002-Fix-integration-with-fish-shell.patch b/debian/patches/0002-Fix-integration-with-fish-shell.patch
new file mode 100644
index 0000000..2d84432
--- /dev/null
+++ b/debian/patches/0002-Fix-integration-with-fish-shell.patch
@@ -0,0 +1,81 @@
+From: Mehdi Dogguy <mehdi at debian.org>
+Date: Tue, 22 Dec 2015 11:47:44 +0100
+Subject: Fix integration with fish shell
+
+Upstream fix: https://github.com/ocaml/opam/commit/df51212ef670f7ab5574373d646e8c4dcc130e4c
+---
+ src/client/opamConfigCommand.ml |  4 +++-
+ src/client/opamState.ml         | 38 ++++++++++++++++++++++++++++++--------
+ 2 files changed, 33 insertions(+), 9 deletions(-)
+
+diff --git a/src/client/opamConfigCommand.ml b/src/client/opamConfigCommand.ml
+index 7925b50..66450ed 100644
+--- a/src/client/opamConfigCommand.ml
++++ b/src/client/opamConfigCommand.ml
+@@ -137,7 +137,9 @@ let print_sexp_env env =
+ let print_fish_env env =
+   List.iter (fun (k,v) ->
+       match k with
+-      | "PATH" | "MANPATH" ->
++      | "PATH" | "MANPATH" | "CDPATH" ->
++        (* This function assumes that `v` does not include any variable expansions
++         * and that the directory names are written in full. See the opamState.ml for details *)
+         let v = OpamMisc.split_delim v ':' in
+         OpamGlobals.msg "set -gx %s %s;\n" k
+           (OpamMisc.sconcat_map " " (Printf.sprintf "%S") v)
+diff --git a/src/client/opamState.ml b/src/client/opamState.ml
+index 281aecc..6249460 100644
+--- a/src/client/opamState.ml
++++ b/src/client/opamState.ml
+@@ -1957,7 +1957,7 @@ let source t ~shell ?(interactive_only=false) f =
+     | `csh ->
+       Printf.sprintf "source %s >& /dev/null || true\n" (file f)
+     | `fish ->
+-      Printf.sprintf ". %s > /dev/null 2> /dev/null or true\n" (file f)
++      Printf.sprintf "source %s > /dev/null 2> /dev/null or true\n" (file f)
+     | _ ->
+       Printf.sprintf ". %s > /dev/null 2> /dev/null || true\n" (file f)
+   in
+@@ -2128,13 +2128,35 @@ let string_of_env_update t shell updates =
+   let fenv = resolve_variable t OpamVariable.Map.empty in
+   let sh   (k,v) = Printf.sprintf "%s=%S; export %s;\n" k v k in
+   let csh  (k,v) = Printf.sprintf "if ( ! ${?%s} ) setenv %s \"\"\nsetenv %s %S\n" k k k v in
+-  let fish (k,v) = match k with
+-    | "PATH" | "MANPATH" ->
+-      let v = OpamMisc.split_delim v ':' in
+-      Printf.sprintf "set -gx %s %s;\n" k
+-        (OpamMisc.sconcat_map " " (Printf.sprintf "%S") v)
+-    | _ ->
+-      Printf.sprintf "set -gx %s %S;\n" k v in
++  let fish (k,v) =
++    (* Fish converts some colon-separated vars to arrays, which have to be treated differently.
++     * Opam only changes PATH and MANPATH but we handle CDPATH for completeness. *)
++    let fish_array_vars = ["PATH"; "MANPATH"; "CDPATH"] in
++    let fish_array_derefs = List.map (fun s -> "$" ^ s) fish_array_vars in
++    if not (List.mem k fish_array_vars) then
++      (* Regular string variables *)
++      Printf.sprintf "set -gx %s %S;\n" k v
++    else
++      (* The MANPATH and CDPATH have default "values" if they are unset and we
++       * must be sure that we preserve these defaults when "appending" to them.
++       * This because Fish has trouble dealing with the case where we want to
++       * have a colon at the start or at the end of the string that gets exported.
++       *  - MANPATH: ""  (default system manpages)
++       *  - CDPATH:  "." (current directory) *)
++      let init_array = match k with
++        | "PATH"    -> "" (* PATH is always set *)
++        | "MANPATH" -> "if [ 0 -eq (count $MANPATH) ]; set -gx MANPATH \"\"; end;\n"
++        | "CDPATH"  -> "if [ 0 -eq (count $CDPATH) ]; set -gx CDPATH \".\"; end;\n"
++        | _         -> assert false in
++      (* Opam assumes that `v` is a string with colons in the middle so we have
++       * to convert that to an array assignment that fish understands.
++       * We also have to pay attention so we don't quote array expansions - that
++       * would replace some colons by spaces in the exported string *)
++      let vs = OpamMisc.split_delim v ':' in
++      let to_arr_element v =
++        if List.mem v fish_array_derefs then v else Printf.sprintf "%S" v in
++      let set_array = Printf.sprintf "set -gx %s %s;\n" k (OpamMisc.sconcat_map " " to_arr_element vs) in
++      (init_array ^ set_array) in
+   let export = match shell with
+     | `zsh
+     | `sh  -> sh
diff --git a/debian/patches/series b/debian/patches/series
index d51b4a5..7d537d8 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
 0001-Port-to-Dose3-4.0.1.patch
+0002-Fix-integration-with-fish-shell.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/opam.git



More information about the Pkg-ocaml-maint-commits mailing list