aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-21 13:09:10 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-21 13:09:10 +1200
commitf7e851d9986a30e3d590d67b23e862a38d427472 (patch)
tree54725167ae5b729071f944e41fdc8ed753cf2283
parent031f0b7be204da3372cd7c87c5d3d420cb57c3c9 (diff)
downloaddotfiles-f7e851d9986a30e3d590d67b23e862a38d427472.tar.gz
dotfiles-f7e851d9986a30e3d590d67b23e862a38d427472.zip
Clean up/extend grep()/ls() extension
-rw-r--r--sh/profile.d/grep.sh2
-rw-r--r--sh/profile.d/ls.sh12
-rw-r--r--sh/shrc.d/grep.sh48
-rw-r--r--sh/shrc.d/ls.sh12
4 files changed, 46 insertions, 28 deletions
diff --git a/sh/profile.d/grep.sh b/sh/profile.d/grep.sh
index d1ef3ba1..d6f9c36b 100644
--- a/sh/profile.d/grep.sh
+++ b/sh/profile.d/grep.sh
@@ -20,7 +20,7 @@
exclude \
exclude-dir
for opt ; do
- grep -Eq -- --"$opt" "$gcd"/help || continue
+ grep -q -- --"$opt" "$gcd"/help || continue
touch -- "$gcd"/"$opt" || exit
done
fi
diff --git a/sh/profile.d/ls.sh b/sh/profile.d/ls.sh
index 0c3754e9..8a255bee 100644
--- a/sh/profile.d/ls.sh
+++ b/sh/profile.d/ls.sh
@@ -13,8 +13,14 @@
# Iterate through some useful options and create files to show they're
# available
- if grep -q -- --color "$lcd"/help ; then
- touch -- "$lcd"/color || exit
- fi
+ set -- block-size \
+ classify \
+ color \
+ human-readable \
+ time-style
+ for opt ; do
+ grep -q -- --"$opt" "$lcd"/help || continue
+ touch -- "$lcd"/"$opt" || exit
+ done
fi
)
diff --git a/sh/shrc.d/grep.sh b/sh/shrc.d/grep.sh
index 2f360716..6fef7701 100644
--- a/sh/shrc.d/grep.sh
+++ b/sh/shrc.d/grep.sh
@@ -5,30 +5,6 @@
# Define function proper
grep() {
- # Add --color if the terminal has at least 8 colors
- [ -e "$HOME"/.cache/grep/color ] &&
- [ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] &&
- set -- --color=auto "$@"
-
- # Add --binary-files=without-match to gracefully skip binary files
- [ -e "$HOME"/.cache/grep/binary-files ] &&
- set -- --binary-files=without-match "$@"
-
- # Add --devices=skip to gracefully skip devices
- [ -e "$HOME"/.cache/grep/devices ] &&
- set -- --devices=skip "$@"
-
- # Add --directories=skip to gracefully skip directories
- [ -e "$HOME"/.cache/grep/directories ] &&
- set -- --directories=skip "$@"
-
- # Add --exclude to ignore .gitignore and .gitmodules files
- [ -e "$HOME"/.cache/grep/exclude ] &&
- set -- \
- --exclude=.gitignore \
- --exclude=.gitmodules \
- "$@"
-
# Add --exclude-dir to ignore version control dot-directories
[ -e "$HOME"/.cache/grep/exclude-dir ] &&
set -- \
@@ -38,6 +14,30 @@ grep() {
--exclude-dir=.svn \
"$@"
+ # Add --exclude to ignore .gitignore and .gitmodules files
+ [ -e "$HOME"/.cache/grep/exclude ] &&
+ set -- \
+ --exclude=.gitignore \
+ --exclude=.gitmodules \
+ "$@"
+
+ # Add --directories=skip to gracefully skip directories
+ [ -e "$HOME"/.cache/grep/directories ] &&
+ set -- --directories=skip "$@"
+
+ # Add --devices=skip to gracefully skip devices
+ [ -e "$HOME"/.cache/grep/devices ] &&
+ set -- --devices=skip "$@"
+
+ # Add --color if the terminal has at least 8 colors
+ [ -e "$HOME"/.cache/grep/color ] &&
+ [ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] &&
+ set -- --color=auto "$@"
+
+ # Add --binary-files=without-match to gracefully skip binary files
+ [ -e "$HOME"/.cache/grep/binary-files ] &&
+ set -- --binary-files=without-match "$@"
+
# Run grep(1) with the concluded arguments
command grep "$@"
}
diff --git a/sh/shrc.d/ls.sh b/sh/shrc.d/ls.sh
index eec25eb7..57f6ed24 100644
--- a/sh/shrc.d/ls.sh
+++ b/sh/shrc.d/ls.sh
@@ -5,11 +5,23 @@
# Define function proper
ls() {
+ # Add --time-style='+%Y-%m-%d %H:%M:%S' to show trailing indicators of the filetype
+ [ -e "$HOME"/.cache/ls/time-style ] &&
+ set -- --time-style='+%Y-%m-%d %H:%M:%S' "$@"
+
# Add --color if the terminal has at least 8 colors
[ -e "$HOME"/.cache/ls/color ] &&
[ "$({ tput colors || tput Co ; } 2>/dev/null)" -ge 8 ] &&
set -- --color=auto "$@"
+ # Add --classify to show trailing indicators of the filetype
+ [ -e "$HOME"/.cache/ls/classify ] &&
+ set -- --classify "$@"
+
+ # Add --block-size=K to always show the filesize in kibibytes
+ [ -e "$HOME"/.cache/ls/block-size ] &&
+ set -- --block-size=K "$@"
+
# Run ls(1) with the concluded arguments
command ls "$@"
}