Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set the HOME environment variable before invoking a command #32

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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])

## [0.2.0] — 2023-12-17 🎄

Expand Down Expand Up @@ -54,4 +59,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
Loading