diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2013-12-11 15:55:08 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2013-12-11 15:55:08 +1300 |
commit | 440888a28a5088dbb9eb8c7015ec454bbdcacbef (patch) | |
tree | bcc7638cba273bc8e11da992788fe0aa4a4356de /bash/bashrc.d | |
parent | Fix trailing whitespace (diff) | |
download | dotfiles-440888a28a5088dbb9eb8c7015ec454bbdcacbef.tar.gz dotfiles-440888a28a5088dbb9eb8c7015ec454bbdcacbef.zip |
Little function to count files
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r-- | bash/bashrc.d/cf.bash | 25 |
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" +} + |