aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2013-11-04 13:16:16 +1300
committerTom Ryder <tom@sanctum.geek.nz>2013-11-04 13:16:16 +1300
commit0e75dc6ddbbf23383dda43e2525de909e4f54a73 (patch)
tree4200e0659b48d8cbd58e7dce1be102b6537c6c62 /bash/bashrc.d
parentFix newline error in cd error print (diff)
downloaddotfiles-0e75dc6ddbbf23383dda43e2525de909e4f54a73.tar.gz
dotfiles-0e75dc6ddbbf23383dda43e2525de909e4f54a73.zip
Wrote a function called 'vis' for editing scripts
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r--bash/bashrc.d/vim.bash33
1 files changed, 33 insertions, 0 deletions
diff --git a/bash/bashrc.d/vim.bash b/bash/bashrc.d/vim.bash
index cad63a46..27758fd2 100644
--- a/bash/bashrc.d/vim.bash
+++ b/bash/bashrc.d/vim.bash
@@ -8,3 +8,36 @@ alias ex='vim -e'
alias vi='vim'
alias view='vim -R'
+# Create or edit a script in $PATH, creating in $HOME/.local/bin
+vis() {
+ local arg cmd file endopts
+ local -a opts cmds files
+
+ # Distinguish options from file arguments
+ endopts=0
+ for arg in "$@"; do
+ if [[ $arg == -- ]]; then
+ endopts=1
+ elif [[ $arg == -* ]] && ! ((endopts)); then
+ opts=("${opts[@]}" "$arg")
+ else
+ cmds=("${cmds[@]}" "$arg")
+ fi
+ done
+
+ # Check all the commands, if they don't exist, we'll create them
+ for cmd in "${cmds[@]}"; do
+ if ! file=$(type -P "${cmd##*/}"); then
+ mkdir -p "$HOME"/.local/bin || exit
+ file="$HOME"/.local/bin/"${cmd##*/}"
+ fi
+ files=("${files[@]}" "$file")
+ done
+
+ # Run Vim with all the options and full path file arguments
+ command vim "${opts[@]}" -- "${files[@]}"
+}
+
+# Complete the vis function with command names
+complete -A command vis
+