File tree Expand file tree Collapse file tree 1 file changed +11
-15
lines changed Expand file tree Collapse file tree 1 file changed +11
-15
lines changed Original file line number Diff line number Diff line change @@ -116,21 +116,17 @@ impl DefaultPrompt {
116116}
117117
118118fn get_working_dir ( ) -> Result < String , std:: io:: Error > {
119- let path = env:: current_dir ( ) ?;
120- let path_str = path. display ( ) . to_string ( ) ;
121- let homedir: String = match env:: var ( "USERPROFILE" ) {
122- Ok ( win_home) => win_home,
123- Err ( _) => match env:: var ( "HOME" ) {
124- Ok ( maclin_home) => maclin_home,
125- Err ( _) => path_str. clone ( ) ,
126- } ,
127- } ;
128- let new_path = if path_str != homedir {
129- path_str. replace ( & homedir, "~" )
130- } else {
131- path_str
132- } ;
133- Ok ( new_path)
119+ let mut path = env:: current_dir ( ) ?;
120+
121+ if let Some ( home) = env:: home_dir ( ) {
122+ if let Ok ( suffix) = path. clone ( ) . strip_prefix ( home) {
123+ path = std:: path:: PathBuf :: from ( "~" ) ;
124+ if !suffix. as_os_str ( ) . is_empty ( ) {
125+ path = path. join ( suffix) ;
126+ }
127+ }
128+ }
129+ Ok ( path. display ( ) . to_string ( ) )
134130}
135131
136132fn get_now ( ) -> String {
You can’t perform that action at this time.
0 commit comments