Skip to content

Commit 7f6f311

Browse files
authored
Add cd replacer to avoid keystrokes
1 parent b81868d commit 7f6f311

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

xontrib/rc_awesome.xsh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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+

0 commit comments

Comments
 (0)