Skip to content

Commit

Permalink
Merge branch 'fish'
Browse files Browse the repository at this point in the history
  • Loading branch information
Canop committed Feb 23, 2019
2 parents a4d3ed5 + 7dc1988 commit 2fbf3d7
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 237 deletions.
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn get_cli_args<'a>() -> clap::ArgMatches<'a> {
.arg(
clap::Arg::with_name("install")
.long("install")
.help("install the br shell function"),
.help("install or reinstall the br shell function"),
)
.arg(
clap::Arg::with_name("only-folders")
Expand Down
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ mod patterns;
mod regex_patterns;
mod screen_text;
mod screens;
mod shell_func;
mod shell_bash;
mod shell_fish;
mod shell_install;
mod skin;
mod skin_conf;
mod spinner;
Expand Down Expand Up @@ -81,7 +83,7 @@ fn configure_log() {
fn run() -> Result<Option<Launchable>, ProgramError> {
configure_log();
let launch_args = cli::read_lauch_args()?;
let should_quit = shell_func::init(&launch_args)?;
let should_quit = shell_install::init(&launch_args)?;
if should_quit {
return Ok(None);
}
Expand Down
40 changes: 40 additions & 0 deletions src/shell_bash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::shell_install::ShellFamily;

pub const BASH: ShellFamily<'static> = ShellFamily {
name: "bash",
sourcing_files: &[".bashrc", ".zshrc"],
version: 1,
script: BASH_FUNC
};

// This script has been tested on bash and zsh.
// It's installed under the bash name (~/.config/broot
// but linked from both the .bashrc and the .zshrc files
const BASH_FUNC: &str = r#"
# This script was automatically generated by the broot function
# More information can be found in https://github.com/Canop/broot/blob/master/documentation.md
# This function starts broot and executes the command
# it produces, if any.
# It's needed because some shell commands, like `cd`,
# have no useful effect if executed in a subshell.
function br {
f=$(mktemp)
(
set +e
broot --outcmd "$f" "$@"
code=$?
if [ "$code" != 0 ]; then
rm -f "$f"
exit "$code"
fi
)
code=$?
if [ "$code" != 0 ]; then
return "$code"
fi
d=$(cat "$f")
rm -f "$f"
eval "$d"
}
"#;
29 changes: 29 additions & 0 deletions src/shell_fish.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use crate::shell_install::ShellFamily;

pub const FISH: ShellFamily<'static> = ShellFamily {
name: "fish",
sourcing_files: &[".config/fish/config.fish"], // idealy we should probably use XDG here...
version: 1,
script: FISH_FUNC
};

const FISH_FUNC: &str = r#"
# This script was automatically generated by the broot function
# More information can be found in https://github.com/Canop/broot/blob/master/documentation.md
# This function starts broot and executes the command
# it produces, if any.
# It's needed because some shell commands, like `cd`,
# have no useful effect if executed in a subshell.
function br
set f (mktemp)
broot --outcmd $f $argv
if test $status -ne 0
rm -f "$f"
return "$code"
end
set d (cat "$f")
rm -f "$f"
eval "$d"
end
"#;
234 changes: 0 additions & 234 deletions src/shell_func.rs

This file was deleted.

Loading

0 comments on commit 2fbf3d7

Please sign in to comment.