Use $XDG_{CONFIG,DATA}_HOME in hooks
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
023ca55493
commit
992cf45dc9
@ -8,12 +8,28 @@
|
|||||||
# $XDG_CONFIG_HOME/calcurse/caldav/hooks/ (~/.config/calcurse/caldav/hooks/) or
|
# $XDG_CONFIG_HOME/calcurse/caldav/hooks/ (~/.config/calcurse/caldav/hooks/) or
|
||||||
# ~/.calcurse/caldav/hooks/ if using ~/.calcurse.
|
# ~/.calcurse/caldav/hooks/ if using ~/.calcurse.
|
||||||
|
|
||||||
cd "$HOME"/.calcurse/
|
data_dir="$HOME/.calcurse"
|
||||||
|
config_dir="$HOME/.calcurse"
|
||||||
|
|
||||||
# If the data directory is under version control, create a Git commit.
|
if [ ! -d "$data_dir" ]; then
|
||||||
if [ -d .git -a -x "$(which git)" ]; then
|
data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/calcurse"
|
||||||
git add apts conf keys todo
|
config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/calcurse"
|
||||||
if ! git diff-index --quiet --cached HEAD; then
|
|
||||||
git commit -m "Automatic commit by the post-sync hook"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Do not do anything when synchronizing with a CalDAV server.
|
||||||
|
[ -f "$data_dir/caldav/lock" ] && exit
|
||||||
|
|
||||||
|
# If the directory is under version control, create a Git commit.
|
||||||
|
commit_dir() {
|
||||||
|
cd "$1" >/dev/null 2>&1 || return
|
||||||
|
shift
|
||||||
|
if [ -d .git ] && command -v git >/dev/null; then
|
||||||
|
git add "$@"
|
||||||
|
if ! git diff-index --quiet --cached HEAD; then
|
||||||
|
git commit -m "Automatic commit by the post-save hook"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
commit_dir "$data_dir" apts todo
|
||||||
|
commit_dir "$config_dir" conf keys
|
||||||
|
@ -2,28 +2,42 @@
|
|||||||
#
|
#
|
||||||
# This is an example hook. It does two things whenever you save the data files:
|
# This is an example hook. It does two things whenever you save the data files:
|
||||||
#
|
#
|
||||||
# 1. Make a commit if the calcurse data directory contains a Git repository.
|
# 1. Make a commit if the calcurse directories contain a Git repository.
|
||||||
# 2. Synchronize with a CalDAV server if calcurse-caldav is configured.
|
# 2. Synchronize with a CalDAV server if calcurse-caldav is configured.
|
||||||
#
|
#
|
||||||
# In order to install this hook, copy this file to
|
# In order to install this hook, copy this file to
|
||||||
# $XDG_CONFIG_HOME/calcurse/hooks/ (~/.config/calcurse/hooks/) or
|
# $XDG_CONFIG_HOME/calcurse/hooks/ (~/.config/calcurse/hooks/) or
|
||||||
# ~/.calcurse/hooks/ if using ~/.calcurse.
|
# ~/.calcurse/hooks/ if using ~/.calcurse.
|
||||||
|
|
||||||
cd "$HOME"/.calcurse/
|
data_dir="$HOME/.calcurse"
|
||||||
|
config_dir="$HOME/.calcurse"
|
||||||
|
|
||||||
|
if [ ! -d "$data_dir" ]; then
|
||||||
|
data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/calcurse"
|
||||||
|
config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/calcurse"
|
||||||
|
fi
|
||||||
|
|
||||||
# Do not do anything when synchronizing with a CalDAV server.
|
# Do not do anything when synchronizing with a CalDAV server.
|
||||||
[ -f caldav/lock ] && exit
|
[ -f "$data_dir/caldav/lock" ] && exit
|
||||||
|
|
||||||
# If the data directory is under version control, create a Git commit.
|
# If the directory is under version control, create a Git commit.
|
||||||
if [ -d .git -a -x "$(which git)" ]; then
|
commit_dir() {
|
||||||
git add apts conf keys todo
|
cd "$1" >/dev/null 2>&1 || return
|
||||||
|
shift
|
||||||
|
if [ -d .git ] && command -v git >/dev/null; then
|
||||||
|
git add "$@"
|
||||||
if ! git diff-index --quiet --cached HEAD; then
|
if ! git diff-index --quiet --cached HEAD; then
|
||||||
git commit -m "Automatic commit by the post-save hook"
|
git commit -m "Automatic commit by the post-save hook"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
commit_dir "$data_dir" apts todo
|
||||||
|
commit_dir "$config_dir" conf keys
|
||||||
|
|
||||||
# Optionally run the CalDAV synchronization script in the background.
|
# Optionally run the CalDAV synchronization script in the background.
|
||||||
if [ -d caldav -a -x "$(which calcurse-caldav)" ]; then
|
cd "$data_dir" || exit
|
||||||
|
if [ -d caldav ] && command -v calcurse-caldav >/dev/null; then
|
||||||
(
|
(
|
||||||
date="$(date +'%b %d %H:%M:%S')"
|
date="$(date +'%b %d %H:%M:%S')"
|
||||||
echo "$date Running calcurse-caldav from the post-save hook..."
|
echo "$date Running calcurse-caldav from the post-save hook..."
|
||||||
|
@ -7,13 +7,15 @@
|
|||||||
# $XDG_CONFIG_HOME/calcurse/hooks/ (~/.config/calcurse/hooks/) or
|
# $XDG_CONFIG_HOME/calcurse/hooks/ (~/.config/calcurse/hooks/) or
|
||||||
# ~/.calcurse/hooks/ if using ~/.calcurse.
|
# ~/.calcurse/hooks/ if using ~/.calcurse.
|
||||||
|
|
||||||
cd "$HOME"/.calcurse/
|
[ -d "$HOME/.calcurse" ] && data_dir="$HOME/.calcurse" || data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/calcurse"
|
||||||
|
|
||||||
|
cd "$data_dir" || exit
|
||||||
|
|
||||||
# Do not do anything when synchronizing with a CalDAV server.
|
# Do not do anything when synchronizing with a CalDAV server.
|
||||||
[ -f caldav/lock ] && exit
|
[ -f caldav/lock ] && exit
|
||||||
|
|
||||||
# Run the CalDAV synchronization script in the background.
|
# Run the CalDAV synchronization script in the background.
|
||||||
if [ -d caldav -a -x "$(which calcurse-caldav)" ]; then
|
if [ -d caldav ] && command -v calcurse-caldav >/dev/null; then
|
||||||
(
|
(
|
||||||
date="$(date +'%b %d %H:%M:%S')"
|
date="$(date +'%b %d %H:%M:%S')"
|
||||||
echo "$date Running calcurse-caldav from the pre-load hook..."
|
echo "$date Running calcurse-caldav from the pre-load hook..."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user