1+ #![ warn( clippy:: all) ]
2+ #![ warn( clippy:: pedantic) ]
3+ #![ allow( clippy:: doc_markdown) ]
4+
15//! Paths and Unix shells
26//!
37//! MacOS, Linux, FreeBSD, and many other OS model their design on Unix,
@@ -95,7 +99,7 @@ pub(crate) trait UnixShell {
9599 // Gives rcs that should be written to.
96100 fn update_rcs ( & self ) -> Vec < PathBuf > ;
97101
98- // By defualt follows POSIX and sources <cargo home>/env
102+ // By default follows POSIX and sources <cargo home>/env
99103 fn add_to_path ( & self ) -> Result < ( ) , anyhow:: Error > {
100104 let source_cmd = self . source_string ( ) ?;
101105 let source_cmd_with_newline = format ! ( "\n {}" , & source_cmd) ;
@@ -249,13 +253,13 @@ impl Fish {
249253 #![ allow( non_snake_case) ]
250254 /// Gets fish vendor config location from `XDG_DATA_DIRS`
251255 /// Returns None if `XDG_DATA_DIRS` is not set or if there is no fis`fish/vendor_conf.d`.d directory found
252- pub fn get_XDG_DATA_DIRS ( ) -> Option < PathBuf > {
253- # [ cfg ( test ) ]
254- return None ;
256+ pub fn get_vendor_config_from_XDG_DATA_DIRS ( ) -> Option < PathBuf > {
257+ // Skip the directory during testing as we don't want to write into the XDG_DATA_DIRS by accident
258+ // TODO: Change the definition of XDG_DATA_DIRS in test so that doesn't happen
255259
260+ // TODO: Set up XDG DATA DIRS in a test to test the location being correct
256261 return process ( )
257262 . var ( "XDG_DATA_DIRS" )
258- // If var is found
259263 . map ( |var| {
260264 var. split ( ':' )
261265 . map ( PathBuf :: from)
@@ -274,14 +278,15 @@ impl UnixShell for Fish {
274278
275279 fn rcfiles ( & self ) -> Vec < PathBuf > {
276280 // As per https://fishshell.com/docs/current/language.html#configuration
277- // Vendor config files should be written to `/fish/vendor_config.d/`
281+ // Vendor config files should be written to `/usr/share/ fish/vendor_config.d/`
278282 // if that does not exist then it should be written to `/usr/share/fish/vendor_conf.d/`
279283 // otherwise it should be written to `$HOME/.config/fish/conf.d/ as per discussions in github issue #478
280284 [
281- #[ cfg( test) ] // Write to test location so we don't pollute during testing.
282- utils:: home_dir ( ) . map ( |home| home. join ( ".config/fish/conf.d/" ) ) ,
283- Self :: get_XDG_DATA_DIRS ( ) ,
285+ // #[cfg(test)] // Write to test location so we don't pollute during testing.
286+ // utils::home_dir().map(|home| home.join(".config/fish/conf.d/")),
287+ Self :: get_vendor_config_from_XDG_DATA_DIRS ( ) ,
284288 Some ( PathBuf :: from ( "/usr/share/fish/vendor_conf.d/" ) ) ,
289+ Some ( PathBuf :: from ( "/usr/local/share/fish/vendor_conf.d/" ) ) ,
285290 utils:: home_dir ( ) . map ( |home| home. join ( ".config/fish/conf.d/" ) ) ,
286291 ]
287292 . iter_mut ( )
@@ -291,17 +296,16 @@ impl UnixShell for Fish {
291296 }
292297
293298 fn update_rcs ( & self ) -> Vec < PathBuf > {
299+ // TODO: Change rcfiles to just read parent dirs
294300 self . rcfiles ( )
295301 . into_iter ( )
296302 . filter ( |rc| {
297- rc. metadata ( ) // Returns error if path doesnt exist so separate check is not needed
298- . map_or ( false , |metadata| {
299- dbg ! ( rc) ;
300- dbg ! ( metadata. permissions( ) ) ;
301- dbg ! ( metadata. permissions( ) . readonly( ) ) ;
302- dbg ! ( ) ;
303- !metadata. permissions ( ) . readonly ( )
304- } )
303+ // We only want to check if the directory exists as in fish we create a new file for every applications env
304+ rc. parent ( ) . map_or ( false , |parent| {
305+ parent
306+ . metadata ( ) // Returns error if path doesn't exist so separate check is not needed
307+ . map_or ( false , |metadata| !metadata. permissions ( ) . readonly ( ) )
308+ } )
305309 } )
306310 . collect ( )
307311 }
@@ -331,8 +335,8 @@ impl UnixShell for Fish {
331335
332336 fn env_script ( & self ) -> ShellScript {
333337 ShellScript {
334- name : "env" ,
335- content : include_str ! ( "env.sh " ) ,
338+ name : "env.fish " ,
339+ content : include_str ! ( "env.fish " ) ,
336340 }
337341 }
338342
@@ -346,13 +350,14 @@ impl UnixShell for Fish {
346350}
347351
348352pub ( crate ) fn legacy_paths ( ) -> impl Iterator < Item = PathBuf > {
349- let zprofiles = Zsh :: zdotdir ( )
353+ let z_profiles = Zsh :: zdotdir ( )
350354 . into_iter ( )
351355 . chain ( utils:: home_dir ( ) )
352356 . map ( |d| d. join ( ".zprofile" ) ) ;
353- let profiles = [ ".bash_profile" , ".profile" ]
357+
358+ let bash_profiles = [ ".bash_profile" , ".profile" ]
354359 . iter ( )
355360 . filter_map ( |rc| utils:: home_dir ( ) . map ( |d| d. join ( rc) ) ) ;
356361
357- profiles . chain ( zprofiles )
362+ bash_profiles . chain ( z_profiles )
358363}
0 commit comments