Skip to content

Commit

Permalink
Install question (#46)
Browse files Browse the repository at this point in the history
* Answer the install question on the same line

* Format Rust code using rustfmt

* Modifications to the notification of shell startup script modification

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
a1ecbr0wn and github-actions[bot] authored Dec 31, 2022
1 parent a73ed9f commit 73360cf
Showing 4 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ To install `bcd` from snap, run the following:
snap install bookmark-cd
```

Snapcraft does not allow write access to the shell init scripts which are required to set up `bcd` so the following commmand should be set up manually in your `~/.bashrc` if you are using bash or `~/.zshrc` if you are using zsh as your shell:
Snapcraft does not allow write access to the shell startup scripts which are required to set up `bcd` so the following commmand should be set up manually in your `~/.bashrc` if you are using bash or `~/.zshrc` if you are using zsh as your shell:

``` sh
# bookmark-cd init block
@@ -67,7 +67,7 @@ then restart your shell.

### Installation issues - Setup your environment

After your installation, you need to restart your shell, your installation should have automatically set up the pointer to `bcd` in your shell init script. If the command `bcd` is not working after your installation or something else has happened to change your shell scripts, running `bookmark-cd` and then restarting your shell should set this correctly.
After your installation, you need to restart your shell, your installation should have automatically set up the pointer to `bcd` in your shell startup script. If the command `bcd` is not working after your installation or something else has happened to change your shell scripts, running `bookmark-cd` and then restarting your shell should set this correctly.

At the moment, only the `bash`, `zsh`, `ksh` and `fish` shells are supported, feel free to [contribute](#contribute) if you are reading this and you need support for a different shell.

2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ pub struct Options {
#[arg(value_parser)]
pub bookmark: Option<String>,

/// Setup the the shell init script
/// Setup the the shell startup script
#[arg(short, long, value_parser, display_order(0), hide(true))]
pub install: bool,

16 changes: 6 additions & 10 deletions src/init/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use home::home_dir;
use std::fs::{File, OpenOptions};
use std::io::prelude::*;
use std::io::{prelude::*, stdout};
use std::path::PathBuf;
use std::process::exit;
use std::process::Command;

mod snap;
use snap::check_in_snap;

// Check that the .bcd data file exists and the shell init script is setup
// Check that the .bcd data file exists and the shell startup script is setup
pub(crate) fn check_bookmarks_file() -> bool {
let mut bookmarks_file = home_dir().unwrap();
bookmarks_file.push(".bcd");
@@ -49,7 +49,8 @@ pub(crate) fn setup_shell(interactive: bool) -> bool {
instructions_shell_script(shell.init, shell.eval);
false
} else {
println!("Do you want to set this up now? [Y/n]");
print!("Do you want to set this up now? [Y/n] ");
let _ = stdout().flush();
let mut reply = String::new();
let _b = std::io::stdin().read_line(&mut reply).unwrap();
reply = reply.trim().to_string();
@@ -100,12 +101,7 @@ fn setup_init_file(interactive: bool, init_file: PathBuf, eval: String) -> bool
writeln!(file).unwrap();
writeln!(file, "# bookmark-cd init block").unwrap();
writeln!(file, "{}", eval).unwrap();
writeln!(file).unwrap();
if interactive {
println!(
"Your shell init script has been set up, restart your shell and type `bcd`"
);
}
println!("\nYour shell startup script has been modified, restart your shell and type `bcd`\n");
true
}
Err(_) => {
@@ -115,7 +111,7 @@ fn setup_init_file(interactive: bool, init_file: PathBuf, eval: String) -> bool
}
} else if interactive {
println!(
"Shell init script [{}] not found",
"Shell startup script [{}] not found",
init_file.to_str().unwrap()
);
false
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ fn main() {
}
} else {
if args.contains(&("init".to_string())) {
// Not called directly, but called by the shell function `bcd` set up in the shell init script
// Not called directly, but called by the shell function `bcd` set up in the shell startup script
init::initialise_shell_script();
exit(0);
}
@@ -39,7 +39,7 @@ fn main() {
};

if options.install {
// a way to try to set up the shell init script when the data file exists but the `bcd` function is not.
// a way to try to set up the shell when the data file exists but the `bcd` function is not.
if init::setup_shell(true) {
exit(0);
} else {

0 comments on commit 73360cf

Please sign in to comment.