Restored symlink
//! be used to launch broot (and thus make it possible to execute
//! some commands, like `cd`, from the starting shell.
//!
+//!
+//! In a correct installation, we have:
+//! - a function declaration script in ~/.local/share/broot/launcher/fish/br.fish
+//! - a link to that script in ~/.config/fish/functions/br.fish
+//! (exact paths depend on XDG variables)
+//!
//! fish stores functions in FISH_CONFIG_DIR/functions (for example,
//! ~/.config/fish/functions) and lazily loads (or reloads) them as
-//! needed. Unfortunately, it doesn't work well with symlinked directories,
-//! so for now we store the function directly in that directory, rather
-//! than linking to BROOT_DIR/launcher/fish.
-
-use std::path::PathBuf;
+//! needed.
-use directories::{BaseDirs, ProjectDirs};
+use {
+ super::ShellInstall,
+ crate::{conf, errors::ProgramError},
+ directories::BaseDirs,
+ directories::ProjectDirs,
+ std::path::PathBuf,
+};
-use super::ShellInstall;
-use crate::errors::ProgramError;
+const NAME: &str = "fish";
+const SCRIPT_FILENAME: &str = "br.fish";
const FISH_FUNC: &str = r#"
# This script was automatically generated by the broot function
@@ -26,14 +34,14 @@ const FISH_FUNC: &str = r#"
# have no useful effect if executed in a subshell.
function br
set -l cmd_file (mktemp)
- if not broot --outcmd $cmd_file $argv
- set -l code $status
- rm -f $cmd_file
- return $code
- else
+ if broot --outcmd $cmd_file $argv
read --local --null cmd < $cmd_file
rm -f $cmd_file
eval $cmd
+ else
+ set -l code $status
+ rm -f $cmd_file
+ return $code
end
end
"#;
@@ -58,10 +66,27 @@ fn get_fish_functions_dir() -> PathBuf {
}
/// return the path to the link to the function script
-fn get_script_path() -> PathBuf {
+///
+/// At version 0.10.4 we change the location of the script:
+/// It was previously with the link, but it's now in
+/// ~/.config/fish/functions/br.fish
+fn get_link_path() -> PathBuf {
get_fish_functions_dir().join("br.fish")
}
+/// return the path to the script containing the function.
+///
+/// At version 0.10.4 we change the location of the script:
+/// It was previously with the link, but it's now in
+/// ~/.local/share/broot/launcher/fish/br.fish
+fn get_script_path() -> PathBuf {
+ conf::app_dirs()
+ .data_dir()
+ .join("launcher")
+ .join(NAME)
+ .join(SCRIPT_FILENAME)
+}
+
/// check for fish shell
///
/// As fish isn't frequently used, we first check that it seems
@@ -75,6 +100,9 @@ pub fn install(si: &mut ShellInstall) -> Result<(), ProgramError> {
info!("fish seems to be installed");
let script_path = get_script_path();
si.write_script(&script_path, FISH_FUNC)?;
+ let link_path = get_link_path();
+ // creating the link may create the fish/conf.d directory
+ si.create_link(&link_path, &script_path)?;
si.done = true;
Ok(())
}
