File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -107,6 +107,20 @@ if $XONSH_INTERACTIVE:
107107 }
108108
109109
110+ # When you copy and paste file path you want to just run `cd ~/path/to/file.txt` without keystrokes on deleting `file.txt`
111+ # so this cd alias replacer is doing that.
112+ aliases ['_cd' ] = aliases ['cd' ]
113+ @aliases .register
114+ @aliases .return_command
115+ def _cd (args ):
116+ if args :
117+ p = @.imp .pathlib .Path (args [0 ])
118+ if (p .exists () and p .is_file ()) or (not p .exists () and p .parent .exists () and '.' in p .name ):
119+ printx (f'cd to parent { p .parent } ' , 'YELLOW' )
120+ return ['_cd' , str (p .parent )]
121+ return ['_cd' ] + args
122+
123+
110124 # Easy way to go back cd-ing.
111125 # Example: `,,` the same as `cd ../../`
112126 for i in range (1 , 6 ):
@@ -354,3 +368,4 @@ if ON_LINUX or ON_DARWIN:
354368
355369
356370
371+
You can’t perform that action at this time.
0 commit comments