Skip to content

Commit

Permalink
[#26] feat: set the HOME environment variable before invoking a comma…
Browse files Browse the repository at this point in the history
…nd (#32)
  • Loading branch information
etorreborre authored Dec 26, 2023
1 parent 311e035 commit 3e51741
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ available [on GitHub][2].
## [Unreleased]

<!-- Add new changes here -->
### 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):
Expand Down Expand Up @@ -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
[0.1.0]: https://github.com/chshersh/zbg/releases/tag/v0.1.0
6 changes: 1 addition & 5 deletions lib/git.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
8 changes: 6 additions & 2 deletions lib/process.ml
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -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
Expand Down

0 comments on commit 3e51741

Please sign in to comment.