Skip to content

Instantly share code, notes, and snippets.

@foooomio
Created February 13, 2015 08:37
Show Gist options
  • Save foooomio/7e3025a336746de3a4ea to your computer and use it in GitHub Desktop.
Save foooomio/7e3025a336746de3a4ea to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu
DOUKUTSU_DIR="${HOME}/Documents/洞窟物語/"
PLIST_DIR="${HOME}/Library/Preferences/"
PLIST_NAME="com.nakiwo.Doukutsu.plist"
backup()
{
local name
local dir
echo -n "バックアップ名を入力: "
read name
dir="${DOUKUTSU_DIR}${name:-$(date +%Y%m%d)}"
mkdir "$dir"
cp "${PLIST_DIR}${PLIST_NAME}" "$dir"
}
restore()
{
cp -if "${DOUKUTSU_DIR}${1}${PLIST_NAME}" "$PLIST_DIR"
killall -u "$USER" cfprefsd
}
main()
{
local dirs
local dir
local i=0
local n
echo "b) [バックアップ]"
dirs=( $(ls -tF "$DOUKUTSU_DIR" | grep /) )
for dir in "${dirs[@]}"
do
echo "${i}) [復元] ${dir%/}"
i=$(( i + 1 ))
done
echo -n "> "
read n
case "$n" in
b) backup ;;
q) echo "quit"; exit 0 ;;
[0-9]|[1-9][0-9]) restore "${dirs[n]}" ;;
*) echo "不正な値"; exit 1 ;;
esac
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment