From f317ed81c2d0b9a2b92e4b46f3a2d94e5142666a Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Tue, 17 Jan 2023 01:38:17 +0100 Subject: [PATCH] git: Add last-changed to mimic github file browser List all files and directories but include the latest commits date and subject, similar to the file browser in web-UIs of services like GitHub. Also sort the entries by the commits date and time to see the most recent changed files/folders at the bottom. --- .config/git/config | 1 + .config/zsh/autoload/git/git-last-changed | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100755 .config/zsh/autoload/git/git-last-changed diff --git a/.config/git/config b/.config/git/config index cfa9f28..0c2ddc4 100644 --- a/.config/git/config +++ b/.config/git/config @@ -27,6 +27,7 @@ filter-repo = !git-filter-repo flog = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/glog\"" https-and-ssh = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-https-and-ssh\"" + last-changed = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-last-changed\"" make-fork = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-make-fork\"" ssync = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-ssync\"" submodule-rm = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-submodule-rm\"" diff --git a/.config/zsh/autoload/git/git-last-changed b/.config/zsh/autoload/git/git-last-changed new file mode 100755 index 0000000..aecdd55 --- /dev/null +++ b/.config/zsh/autoload/git/git-last-changed @@ -0,0 +1,15 @@ +#!/usr/bin/env zsh +# +# List all files and directories but include the latest commits date and +# subject, similar to the file browser in web-UIs of services like GitHub. Also +# sort the entries by the commits date and time to see the most recent changed +# files/folders at the bottom. + +ls -1 "$@" \ +| while read -r line; do + git_info="$(git log -1 --format=$'%ci\t%s' "$line")" + printf "%s\t%s\n" "$line" "$git_info" +done \ +| sort -r -t$'\t' -k2,2 \ +| column -s$'\t' -t \ +| cut -c -"$COLUMNS"