Created
June 1, 2019 08:04
-
-
Save Leedehai/af2c8dede5a63f17e180b36c0b26eee1 to your computer and use it in GitHub Desktop.
vim <=> ls: to relieve a common command typo headache when working in terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This contains two files.. the ls proxy and the vim proxy | |
# Problem I wanted to solve: | |
# when working in terminal, sometimes I mistake ls with vim, or vice versa, when I | |
# am inspecting a directory recursively. When this happens, I have to retype the | |
# command. Yes, '!$' helps me to re-use the previous argument, but I still wish the | |
# experience could be smoother. | |
# Solution: | |
# make ls and vim interchangeable by delegating ls and vim to proxy scripts, and set | |
# alias 'ls' and 'vim' to these scripts. | |
### ls.sh -- the ls proxy | |
#!/usr/bin/env sh | |
if [ $# -eq 1 ] && [ -f $1 ]; then | |
read -p "'ls' => 'vim'? [y/N] " consent | |
case $consent in | |
[Yy]) | |
vim $1 | |
break | |
;; | |
*) | |
exit 1 | |
;; | |
esac | |
else | |
ls -G $@ # -G: color | |
fi | |
### vim.sh -- the vim proxy | |
#!/usr/bin/env sh | |
if [ $# -eq 1 ] && [ -d $1 ]; then | |
read -p "'vim' => 'ls'? [y/N] " consent | |
case $consent in | |
[Yy]) | |
ls -G $1 # -G: color | |
break | |
;; | |
*) | |
exit 1 | |
;; | |
esac | |
else | |
vim $@ | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment