Skip to content

Latest commit

 

History

History
76 lines (59 loc) · 1.9 KB

examples.md

File metadata and controls

76 lines (59 loc) · 1.9 KB

Examples

disk usage (file sizes) (aka ncdu alternative)

fd -HI -tf --strip-cwd-prefix --exec-batch du -b --apparent-size \
     | nctok --number-delimiter $'\t'

git commits count per file

git log --name-only --format="" \
    | grep -v '^$' \
    | perl -lne 'print if -e' \
    | sort | uniq -c | sed 's/^\s*//' | nctok

lines of code, comments, blank lines (with tokei)

_tokei_helper() {
    target="$1"; shift
    tokei -Cfo json $* \
        | jq -r '.[].reports[] | "\(.stats.'$target') \(.name)"' \
        | nctok
}

# by code
alias bycode="_tokei_helper code"
# by comments
alias bycmnts="_tokei_helper comments"
# by blanks
alias byblanks="_tokei_helper blanks"

Also, tokei supports filtering by language (read more in tokei's help), and we can pass it to our aliases:

bycode -t c++
bycode -t shell
bycode -t c++,rust

lines count, words count (with coreutils wc)

# by lines
fd -HI -tf --strip-cwd-prefix --exec-batch wc -l --total=never \
    | sed 's/^\s*//' | nctok
# by words
fd -HI -tf --strip-cwd-prefix --exec-batch wc -w --total=never \
    | sed 's/^\s*//' | nctok

matches count per file

rg "your_pattern" --count-matches --null | awk -F '\0' '{print $2, $1}' | nctok

files count in directory

(actually just adding "1" for each file)

fd -tf | sed 's/^/1 /' | nctok