aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2013-12-11 15:55:08 +1300
committerTom Ryder <tom@sanctum.geek.nz>2013-12-11 15:55:08 +1300
commit440888a28a5088dbb9eb8c7015ec454bbdcacbef (patch)
treebcc7638cba273bc8e11da992788fe0aa4a4356de /bash/bashrc.d
parentFix trailing whitespace (diff)
downloaddotfiles-440888a28a5088dbb9eb8c7015ec454bbdcacbef.tar.gz
dotfiles-440888a28a5088dbb9eb8c7015ec454bbdcacbef.zip
Little function to count files
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r--bash/bashrc.d/cf.bash25
1 files changed, 25 insertions, 0 deletions
diff --git a/bash/bashrc.d/cf.bash b/bash/bashrc.d/cf.bash
new file mode 100644
index 00000000..2de37736
--- /dev/null
+++ b/bash/bashrc.d/cf.bash
@@ -0,0 +1,25 @@
+# Count files
+cf() {
+ local dir dgs ngs
+ local -a files
+
+ # Record current state of dotglob and nullglob
+ shopt -pq dotglob && dgs=1
+ shopt -pq nullglob && ngs=1
+
+ # Specify directory to check
+ dir=${1:-$PWD}
+
+ # Retrieve the files array
+ shopt -s dotglob nullglob
+ files=("$dir"/*)
+
+ # Reset our options
+ ((dgs)) && shopt -s dotglob
+ ((ngs)) && shopt -s nullglob
+
+ # Print result
+ printf 'cf: %'\''.f files in %s\n' \
+ "${#files[@]}" "$dir"
+}
+