From 691a9a2bc9e9ec279bbcdc3d0873db61b72767b1 Mon Sep 17 00:00:00 2001 From: CodeFalling Date: Sat, 23 Aug 2014 19:13:11 +0800 Subject: [PATCH] new plugin:better alias --- plugins/README.markdown | 1 + plugins/better-alias/README.md | 16 ++++++++++++++++ plugins/better-alias/balias.fish | 11 +++++++++++ 3 files changed, 28 insertions(+) create mode 100644 plugins/better-alias/README.md create mode 100644 plugins/better-alias/balias.fish diff --git a/plugins/README.markdown b/plugins/README.markdown index d15900b..4eb0214 100644 --- a/plugins/README.markdown +++ b/plugins/README.markdown @@ -2,6 +2,7 @@ * __android-sdk__ – [Android SDK](http://developer.android.com/sdk/index.html) integration. * __archlinux__ – Provides a number of plugins to make using Arch Linux easier. * __autojump__ – Makes navigating filesystem much faster. See [autojump article](https://github.com/joelthelion/autojump/wiki) and [video](https://www.youtube.com/watch?v=tnNyoMGnbKg). Bindings only, autojump needs to be installed separately. +* __better-alias__ - Provide alias with auto completion. * __brew__ – [Homebrew](http://brew.sh/) integration. * __bundler__ – Use Ruby's [Bundler](http://bundler.io/) automatically for some commands. * __ccache__ – Enable [ccache](http://ccache.samba.org/) to speed up compilation. diff --git a/plugins/better-alias/README.md b/plugins/better-alias/README.md new file mode 100644 index 0000000..348cf1e --- /dev/null +++ b/plugins/better-alias/README.md @@ -0,0 +1,16 @@ +# A better alias provide completion + +Use `balias` instead of `alias`,you can get same completion meanwhile you set alias. + +# Example + +``` +balias apti 'sudo apt-get install' +balias gc 'git checkout' +``` + +Then,you will get + +![apti](http://www.geekpics.net/images/2014/08/23/TJn6kfBY.png) + +![gc](http://www.geekpics.net/images/2014/08/23/655x76xcPJolvxqra.png.pagespeed.ic.4S9hgPfZ53.png) diff --git a/plugins/better-alias/balias.fish b/plugins/better-alias/balias.fish new file mode 100644 index 0000000..d818791 --- /dev/null +++ b/plugins/better-alias/balias.fish @@ -0,0 +1,11 @@ +function balias --argument alias command + eval 'alias $alias $command' + if expr match $command '^sudo '>/dev/null + set command (expr substr + $command 6 (expr length $command)) + end + complete -c $alias -xa "( + set -l cmd (commandline -pc | sed -e 's/^ *\S\+ *//' ); + complete -C\"$command \$cmd\"; + )" +end +