1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use {
super::ShellInstall,
crate::{conf, errors::ProgramError},
directories::BaseDirs,
directories::ProjectDirs,
std::path::PathBuf,
};
const NAME: &str = "fish";
const SCRIPT_FILENAME: &str = "br.fish";
const FISH_FUNC: &str = r#"
# This script was automatically generated by the broot program
# More information can be found in https://github.com/Canop/broot
# 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 -l cmd_file (mktemp)
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
"#;
pub fn get_script() -> &'static str {
FISH_FUNC
}
fn get_fish_dir() -> PathBuf {
if let Some(base_dirs) = BaseDirs::new() {
let fish_dir = base_dirs.home_dir().join(".config/fish");
if fish_dir.exists() {
return fish_dir;
}
}
ProjectDirs::from("fish", "fish", "fish")
.expect("Unable to find configuration directories")
.config_dir()
.to_path_buf()
}
fn get_fish_functions_dir() -> PathBuf {
get_fish_dir().join("functions")
}
fn get_link_path() -> PathBuf {
get_fish_functions_dir().join("br.fish")
}
fn get_script_path() -> PathBuf {
conf::app_dirs()
.data_dir()
.join("launcher")
.join(NAME)
.join(SCRIPT_FILENAME)
}
pub fn install(si: &mut ShellInstall) -> Result<(), ProgramError> {
let fish_dir = get_fish_dir();
if !fish_dir.exists() {
debug!("no fish config directory. Assuming fish isn't used.");
return Ok(());
}
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();
si.create_link(&link_path, &script_path)?;
si.done = true;
Ok(())
}