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

Revert "Intermediate source <(mcfly init *sh) during initialisation. Fixes #254, #219, #239" #257

Merged
merged 1 commit into from
May 9, 2022
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
39 changes: 9 additions & 30 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,28 @@ use super::settings::InitMode;

pub struct Init {}

// Intermediating a `source <(...)` step is important so that the actual init
// scripts don't have too much power in `.bashrc` or `.zshrc` when `eval()`'d. For
// instance eval'ing `return 0` returns from the _entire_ .bashrc/.zshrc script,
// not just the mcfly init script.
//
// Perhaps just asking users to directly `source <(mcfly init bash --print_full_init)`
// is better, but we now also need to be backward compatible for those that already
// have `eval "$(mcfly init bash)"` in their config.
//
// See: https://github.com/cantino/mcfly/issues/254
const BASH_SOURCE_STANZA: &str = "source <(mcfly init bash --print_full_init)";
const ZSH_SOURCE_STANZA: &str = "source <(mcfly init zsh --print_full_init)";

impl Init {
pub fn new(init_mode: &InitMode, is_print_full_init: bool) -> Self {
pub fn new(init_mode: &InitMode) -> Self {
match init_mode {
InitMode::Bash => {
Init::init_bash(is_print_full_init);
Init::init_bash();
}
InitMode::Zsh => {
Init::init_zsh(is_print_full_init);
Init::init_zsh();
}
InitMode::Fish => {
Init::init_fish();
}
}
Self {}
}
pub fn init_bash(is_print_full_init: bool) {
if is_print_full_init {
let script = include_str!("../mcfly.bash");
print!("{}", script);
} else {
print!("{}", BASH_SOURCE_STANZA);
}
pub fn init_bash() {
let script = include_str!("../mcfly.bash");
print!("{}", script);
}
pub fn init_zsh(is_print_full_init: bool) {
if is_print_full_init {
let script = include_str!("../mcfly.zsh");
print!("{}", script);
} else {
print!("{}", ZSH_SOURCE_STANZA);
}
pub fn init_zsh() {
let script = include_str!("../mcfly.zsh");
print!("{}", script);
}
pub fn init_fish() {
let script = include_str!("../mcfly.fish");
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn handle_move(settings: &Settings) {
}

fn handle_init(settings: &Settings) {
Init::new(&settings.init_mode, settings.print_full_init);
Init::new(&settings.init_mode);
}

fn main() {
Expand Down
6 changes: 0 additions & 6 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ pub struct Settings {
pub interface_view: InterfaceView,
pub result_sort: ResultSort,
pub disable_menu: bool,
pub print_full_init: bool,
}

impl Default for Settings {
Expand Down Expand Up @@ -117,7 +116,6 @@ impl Default for Settings {
interface_view: InterfaceView::Top,
result_sort: ResultSort::Rank,
disable_menu: false,
print_full_init: false,
}
}
}
Expand Down Expand Up @@ -245,9 +243,6 @@ impl Settings {
.help("Shell to init — one of bash, zsh, or fish")
.possible_values(&["bash", "zsh", "fish"])
.required(true))
.arg(Arg::with_name("print_full_init")
.long("print_full_init")
.help("Output full init code as opposed to just `source <(...)`"))
)
.get_matches();

Expand Down Expand Up @@ -465,7 +460,6 @@ impl Settings {

("init", Some(init_matches)) => {
settings.mode = Mode::Init;
settings.print_full_init = init_matches.is_present("print_full_init");
match init_matches.value_of("shell").unwrap() {
"bash" => {
settings.init_mode = InitMode::Bash;
Expand Down