diff options
Diffstat (limited to 'bash')
-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" +} + |