コミットしわすれている git リポジトリをきれいにした
そもそもどんなリポジトリを作っていたかも謎になっていたので、探すところからやった。
cron で実行して通知するために、DBUS_SESSION_BUS_ADDRESSを探すところが苦労した。
#!/usr/bin/env zsh
SESSION_MANAGER=xfce4-session
SCRIPT_NAME="yomogi-git-commit-reminder"
NOTIFY_LIFE_TIME=5000
function LIST_GIT_DIRS() {
find $HOME -xdev -type d -name .git 2>/dev/null
}
function create_remind_reports() {
LINE=''
LIST_GIT_DIRS | while read git_dir
do
CHANGED_LINES=`git --git-dir="$git_dir" --work-tree="$git_dir/.." status --porcelain | wc -l`
if [ $CHANGED_LINES -gt 0 ]
then
LINE=$LINE" `printf "%05d" $CHANGED_LINES` ${git_dir%/*} \n"
fi
done
echo $LINE;
}
function output_report() {
if [ "$VERBOSE" = "TRUE" ]
then
echo $REPORTS
fi
if [ "$NOTIFY" = "TRUE" ]
then
PID=$(pgrep xfce4-session)
dbus=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
export DBUS_SESSION_BUS_ADDRESS=$dbus
/usr/bin/notify-send --urgency=low --expire-time=$NOTIFY_LIFE_TIME --category=git \
--icon=$HOME/var/image/Git-Icon-White.png \
'not commited git repos' $REPORTS
fi;
}
###
# main section
VERBOSE="TRUE"
while getopts nq OPT
do
case $OPT in
"n" ) NOTIFY="TRUE" ;;
"q" ) VERBOSE="FALSE" ;;
* ) echo "unexpected arg $OPT"
exit 1;;
esac
done
REPORTS=`create_remind_reports`
output_report "$REPORTS"
こんな感じで出てくる。
yomogi-git-commit-reminder.sh -n
00003 /hoge/fuga
00013 /piyo
-n をつけると通知が出るようにして crontab に追加した。
emacs で python を書く設定をする
https://www.emacswiki.org/emacs/PythonProgrammingInEmacs を参考に書く。