shortcut.py: A Command Line Script to Provide Macro
Typical usage
go
to some directory use short alias
> pwd
/home/jw
> go prj0
cd /work/projects/design/master-branch/
> pwd
/work/projects/design/master-branch/
run
a serial of commands use short alias
> run vnc
ssh -L 5901:remote-internal-server-name:5901 jw@remote-gateway-ip
vncviewer remote-internal-server-name
Search available alias
Here .
dot is used to replace *
star because zsh
will try to expand *
by default.
> go
prj0
> go p.
prj0
> run
vnc
Auto-correction
shortcut.py
uses difflib.get_close_matches
to auto-correct the alias.
Configuration files
- Location
~/.shortcut/
- Naming conventions
- Ex.
go.cfg
forgo
command andrun.cfg
forrun
command
- Ex.
- Format
// comments
// filename: ~/.shortcut/go.cfg
# prj0
cd /work/projects/design/master-branch/
// filename: ~/.shortcut/run.cfg
# vnc
ssh -L 5901:remote-internal-server-name:5901 jw@remote-gateway-ip
vncviewer remote-internal-server-name
How-to
- Download shortcut.py to
~/script/shortcut.py
- Create your own
~/.shortcut/*.cfg
file - Add the following lines into your
.zshrc
shortcut () {
local cmd
cmd=$(python3 ~/script/shortcut.py $@)
eval ${cmd}
}
alias go=`shortcut go`
alias run=`shortcut run`