Skip to content

Scripts

Dayne edited this page Feb 1, 2020 · 2 revisions

List file extensions in current git repo

git ls-files | awk '{print tolower()}' | awk -F '/' '{print $NF}' | awk -F '.' '{print $NF}' | sort | uniq -c | sort -n

  • git ls-files - Lists all files in the current git repo.
  • awk '{print tolower()}' - prints the file path to lower case.
  • awk -F '/' '{print $NF}' - splits the file path by '/' and prints the last item in the path.
  • awk -F '.' '{print $NF}' - splits the file by '.' and prints the file extension (last item)
  • sort - sorts the file extensions so the following uniq can aggregate them.
  • uniq -c - aggregates the file extensions into a count and prints the count + file_extension
  • sort -n - sorts the counts by numerical value.

Re-run arbitrary script on save of particular file types

git ls-files | grep -i '.*\.\(js\|jsx\|css\|scss\|rb\|erb\|haml\|feature\)$' | entr -scr 'echo "hello"'

  • git ls-files - Lists all files in the current git repo.
  • grep -i '.*\.\(js\|jsx\|css\|scss\|rb\|erb\|haml\|feature\)$' - filters the file extensions we are interested in.
  • entr -scr 'echo "hello"' - entr watches the given filepaths for changes and then runs the given command
Clone this wiki locally