1
+ use nix_rs:: env:: OS ;
1
2
use serde:: { Deserialize , Serialize } ;
2
3
use std:: {
4
+ borrow:: Cow ,
3
5
collections:: HashMap ,
4
6
hash:: Hash ,
5
7
path:: { Path , PathBuf } ,
@@ -26,13 +28,14 @@ impl Default for ShellCheck {
26
28
impl Checkable for ShellCheck {
27
29
fn check (
28
30
& self ,
29
- _nix_info : & nix_rs:: info:: NixInfo ,
31
+ nix_info : & nix_rs:: info:: NixInfo ,
30
32
_flake : Option < & nix_rs:: flake:: url:: FlakeUrl > ,
31
33
) -> Vec < ( & ' static str , Check ) > {
32
34
if !self . enable {
33
35
return vec ! [ ] ;
34
36
}
35
- let user_shell_env = match CurrentUserShellEnv :: new ( ) {
37
+ let os = & nix_info. nix_env . os ;
38
+ let user_shell_env = match CurrentUserShellEnv :: new ( os) {
36
39
Ok ( shell) => shell,
37
40
Err ( err) => {
38
41
tracing:: error!( "Skipping shell dotfile check! {:?}" , err) ;
@@ -46,8 +49,8 @@ impl Checkable for ShellCheck {
46
49
} ;
47
50
48
51
// Iterate over each dotfile and check if it is managed by Nix
49
- let mut managed: HashMap < & ' static str , PathBuf > = HashMap :: new ( ) ;
50
- let mut unmanaged: HashMap < & ' static str , PathBuf > = HashMap :: new ( ) ;
52
+ let mut managed: HashMap < String , PathBuf > = HashMap :: new ( ) ;
53
+ let mut unmanaged: HashMap < String , PathBuf > = HashMap :: new ( ) ;
51
54
for ( name, path) in user_shell_env. dotfiles {
52
55
if super :: direnv:: is_path_in_nix_store ( & path) {
53
56
managed. insert ( name, path. clone ( ) ) ;
@@ -88,15 +91,15 @@ struct CurrentUserShellEnv {
88
91
/// Current shell
89
92
shell : Shell ,
90
93
/// *Absolute* paths to the dotfiles
91
- dotfiles : HashMap < & ' static str , PathBuf > ,
94
+ dotfiles : HashMap < String , PathBuf > ,
92
95
}
93
96
94
97
impl CurrentUserShellEnv {
95
98
/// Get the current user's shell environment
96
- fn new ( ) -> Result < Self , ShellError > {
99
+ fn new ( os : & OS ) -> Result < Self , ShellError > {
97
100
let home = PathBuf :: from ( std:: env:: var ( "HOME" ) ?) ;
98
101
let shell = Shell :: current_shell ( ) ?;
99
- let dotfiles = shell. get_dotfiles ( & home) ?;
102
+ let dotfiles = shell. get_dotfiles ( os , & home) ?;
100
103
let v = CurrentUserShellEnv {
101
104
home,
102
105
shell,
@@ -127,6 +130,7 @@ enum ShellError {
127
130
enum Shell {
128
131
Zsh ,
129
132
Bash ,
133
+ Nushell ,
130
134
}
131
135
132
136
impl Shell {
@@ -147,25 +151,43 @@ impl Shell {
147
151
match shell_name. as_ref ( ) {
148
152
"zsh" => Ok ( Shell :: Zsh ) ,
149
153
"bash" => Ok ( Shell :: Bash ) ,
154
+ "nu" => Ok ( Shell :: Nushell ) ,
150
155
_ => Err ( ShellError :: UnsupportedShell ) ,
151
156
}
152
157
}
153
158
154
159
/// Get shell dotfiles
155
- fn dotfile_names ( & self ) -> Vec < & ' static str > {
160
+ fn dotfile_names ( & self , os : & OS ) -> Vec < String > {
156
161
match & self {
157
- Shell :: Zsh => vec ! [ ".zshrc" , ".zshenv" , ".zprofile" , ".zlogin" , ".zlogout" ] ,
158
- Shell :: Bash => vec ! [ ".bashrc" , ".bash_profile" , ".profile" ] ,
162
+ Shell :: Zsh => vec ! [
163
+ ".zshrc" . into( ) ,
164
+ ".zshenv" . into( ) ,
165
+ ".zprofile" . into( ) ,
166
+ ".zlogin" . into( ) ,
167
+ ".zlogout" . into( ) ,
168
+ ] ,
169
+ Shell :: Bash => vec ! [ ".bashrc" . into( ) , ".bash_profile" . into( ) , ".profile" . into( ) ] ,
170
+ Shell :: Nushell => {
171
+ let base = match os {
172
+ // https://www.nushell.sh/book/configuration.html#configuration-overview
173
+ OS :: MacOS { .. } => "Library/Application Support/nushell" ,
174
+ _ => ".config/nushell" ,
175
+ } ;
176
+ vec ! [ "env.nu" , "config.nu" , "login.nu" ]
177
+ . iter ( )
178
+ . map ( |f| format ! ( "{}/{}" , base, f) . into ( ) )
179
+ . collect ( )
180
+ }
159
181
}
160
182
}
161
183
162
184
/// Get the currently existing dotfiles under $HOME
163
185
///
164
186
/// Returned paths will be absolute (i.e., symlinks are resolved).
165
- fn get_dotfiles ( & self , home_dir : & Path ) -> std:: io:: Result < HashMap < & ' static str , PathBuf > > {
187
+ fn get_dotfiles ( & self , os : & OS , home_dir : & Path ) -> std:: io:: Result < HashMap < String , PathBuf > > {
166
188
let mut paths = HashMap :: new ( ) ;
167
- for dotfile in self . dotfile_names ( ) {
168
- match std:: fs:: canonicalize ( home_dir. join ( dotfile) ) {
189
+ for dotfile in self . dotfile_names ( os ) {
190
+ match std:: fs:: canonicalize ( home_dir. join ( & dotfile) ) {
169
191
Ok ( path) => {
170
192
paths. insert ( dotfile, path) ;
171
193
}
0 commit comments