]> arthur.barton.de Git - ax-zsh.git/commitdiff
New plugin "grep"
authorAlexander Barton <alex@barton.de>
Sun, 19 Jul 2015 14:44:47 +0000 (16:44 +0200)
committerAlexander Barton <alex@barton.de>
Sun, 19 Jul 2015 14:44:47 +0000 (16:44 +0200)
This plugin is a default plugin, therefore loaded automatically.

ax.zsh
plugins/grep/grep.zshrc [new file with mode: 0644]

diff --git a/ax.zsh b/ax.zsh
index d061aea1a173e328fcc5000d81796ef207e0c1c6..072adf55e18607b9c444bb86c6bbcbc38050b203 100644 (file)
--- a/ax.zsh
+++ b/ax.zsh
@@ -69,6 +69,7 @@ if ! typeset +m axzsh_default_plugins | fgrep array >/dev/null 2>&1; then
        axzsh_default_plugins=(
                byebye
                correction
+               grep
                history
                less
                ls
diff --git a/plugins/grep/grep.zshrc b/plugins/grep/grep.zshrc
new file mode 100644 (file)
index 0000000..f83468a
--- /dev/null
@@ -0,0 +1,30 @@
+# AX-ZSH: Alex' Modular ZSH Configuration
+# grep.zshrc: Setup grep
+
+# Make sure that "grep(1)" is installed
+(( $+commands[grep] )) || return
+
+grep-flag-available() {
+       echo | grep "$1" "" >/dev/null 2>&1
+}
+
+grep_options=""
+vcs_folders="{.bzr,.cvs,.git,.hg,.svn}"
+
+# Color
+if grep-flag-available "--color=auto"; then
+       grep_options+=" --color=auto"
+fi
+
+# Exclude VCS folders
+if grep-flag-available "--exclude-dir=.csv"; then
+       grep_options+=" --exclude-dir=$vcs_folders"
+elif grep-flag-available "--exclude=.csv"; then
+       grep_options+=" --exclude=$vcs_folders"
+fi
+
+[[ -n "$options" ]] && alias grep="grep${grep_options}"
+
+unfunction grep-flag-available
+unset grep_options
+unset vcs_folders