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

init: change shell setup defaut to true #5456

Merged
merged 2 commits into from
May 8, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ users)
* [BUG] Fix display of pinned packages in action list [#5079 @rjbou]
* [BUG] Fix spaces in root and switch dirs [#5203 @jonahbeckford]
* Use menu for init setup [#5057 @AltGr; #5217 @dra27]
* ✘ Change default from no to yes for shell update [#5456 @rjbou]
* Do not show --yes and --no as special global options when using cmdliner >= 1.1 [#5269 @kit-ty-kate]
* ◈ Add `tree` subcommand to display a dependency tree of currently installed packages [#5171 @cannorin - fix #3775]
* ◈ `tree` subcommand now supports `--json` option [#5303 @cannorin - fix #5298]
Expand All @@ -46,6 +47,7 @@ users)
* [BUG] Fix `opam init` and `opam init --reinit` when the `jobs` variable has been set in the opamrc or the current config. [#5056 @rjbou]
* Use `.opam` from `%HOME%` or `%USERPROFILE%` on Windows, only if found; otherwise use `%LOCALAPPDATA%\opam` as root. [#5212 @dra27]
* Display actual location of OPAMROOT in `opam init` if `--root` or `OPAMROOT` have been set [#5212 @dra27 - fix #4992]
* Surround and add a comment describing the role of the lines added to the ~/.profile or equivalent [#5456 @kit-ty-kate]

## Config report
* [BUG] Don't fail is no switch is set [#5198 @rjbou]
Expand Down
25 changes: 16 additions & 9 deletions src/state/opamEnv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -792,21 +792,28 @@ let update_dot_profile root dot_profile shell =
pretty_dot_profile
| `yes ->
let init_file = init_file shell in
let body =
let old_body =
if OpamFilename.exists dot_profile then
OpamFilename.read dot_profile
else
"" in
OpamConsole.msg " Updating %s.\n" pretty_dot_profile;
bash_src();
let body =
let count_lines str = List.length (String.split_on_char '\n' str) in
let opam_section =
Printf.sprintf
"%s\n\n\
# opam configuration\n\
%s"
(OpamStd.String.strip body) (source root shell init_file) in
OpamFilename.write dot_profile body

"\n\n\
# BEGIN opam configuration\n\
# This is useful if you're using opam as it adds:\n\
# - the correct directories to the PATH\n\
# - auto-completion for the opam binary\n\
# This section can be safely removed at any time if needed.\n\
%s\
# END opam configuration\n"
(source root shell init_file) in
OpamFilename.write dot_profile (old_body ^ opam_section);
OpamConsole.msg " Added %d lines after line %d in %s.\n"
(count_lines opam_section - 1) (count_lines old_body) pretty_dot_profile

let update_user_setup root ?dot_profile shell =
if dot_profile <> None then (
Expand Down Expand Up @@ -873,7 +880,7 @@ let setup
match
OpamConsole.menu "Do you want opam to configure %s?"
(OpamConsole.colorise `bold (string_of_shell shell))
~default ~no:`No ~options:[
~default ~no:`Yes ~options:[
`Yes, Printf.sprintf "Yes, update %s"
(OpamConsole.colorise `cyan (OpamFilename.prettify dot_profile));
`No_hooks, Printf.sprintf "Yes, but don't setup any hooks. You'll \
Expand Down