diff --git a/CHANGELOG.md b/CHANGELOG.md index 8acb9c2..1002af9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ available [on GitHub][2]. ## [Unreleased] +### Fixed + +- [#26](https://github.com/chshersh/zbg/issues/26): + Set the `HOME` environment variable before calling external commands. + (by [@etorreborre]) ### Changed - [#31](https://github.com/chshersh/zbg/pull/31): @@ -60,4 +65,4 @@ Initial release prepared by [@chshersh]. [Unreleased]: https://github.com/chshersh/zbg/compare/v0.2.0...HEAD [0.2.0]: https://github.com/chshersh/zbg/releases/tag/v0.2.0 -[0.1.0]: https://github.com/chshersh/zbg/releases/tag/v0.1.0 \ No newline at end of file +[0.1.0]: https://github.com/chshersh/zbg/releases/tag/v0.1.0 diff --git a/lib/git.ml b/lib/git.ml index f753c35..fbde53c 100644 --- a/lib/git.ml +++ b/lib/git.ml @@ -19,11 +19,7 @@ let branch_or_main (branch_opt : string option) : string = (* Read user login from user.login in git config. *) let get_login () : string option = - let home_dir = Unix.getenv "HOME" in - let login = - Process.proc_stdout - @@ Printf.sprintf "HOME=%s git config user.login" home_dir - in + let login = Process.proc_stdout "git config user.login" in if String.is_empty login then None else Some login let mk_branch_description (description : string list) : string = diff --git a/lib/process.ml b/lib/process.ml index c738705..6361493 100644 --- a/lib/process.ml +++ b/lib/process.ml @@ -1,5 +1,9 @@ +let mk_home_cmd cmd = + let home_dir = Unix.getenv "HOME" in + Printf.sprintf "HOME=%s %s" home_dir cmd + let proc_silent cmd = - let _exit_code = Unix.system cmd in + let _exit_code = Unix.system (mk_home_cmd cmd) in () let proc cmd = @@ -16,7 +20,7 @@ let collect_chan (channel : in_channel) : string = let proc_stdout cmd = let ((proc_stdout, _proc_stdin, _proc_stderr) as process) = - Unix.open_process_full cmd [||] + Unix.open_process_full (mk_home_cmd cmd) [||] in let stdout_result = collect_chan proc_stdout in let _ = Unix.close_process_full process in