OSDN Git Service

sample yashrc: Warn on crontab -r
authormagicant <magicant@048f04df-13f5-43d7-8114-9f9ceecaec24>
Sat, 21 Dec 2019 14:30:23 +0000 (14:30 +0000)
committermagicant <magicant@048f04df-13f5-43d7-8114-9f9ceecaec24>
Sat, 21 Dec 2019 14:30:23 +0000 (14:30 +0000)
Some users accidentally remove their crontab by typing "crontab -r" when
they intend to edit it by "crontab -e". To prevent unrecoverable loss,
a wrapper function for the crontab command is now installed in the
sample yashrc.

git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/yash/yash/trunk@4007 048f04df-13f5-43d7-8114-9f9ceecaec24

NEWS
NEWS.ja
share/initialization/common

diff --git a/NEWS b/NEWS
index e1e98b6..038d60c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,10 @@ Yash 2.50
 
   *  Line-editing no longer hangs when the terminfo database maps a
      key to an empty string.
+  .  Updated the sample initialization script (yashrc):
+    +  A wrapper function for the "crontab" command is now installed
+       to prevent accidental removal by "crontab -r" where the user
+       intends "crontab -e".
   .  Updated completion scripts:
     +  git-rebase: support new options in Git 2.24.0.
 
diff --git a/NEWS.ja b/NEWS.ja
index 1d6eaed..de470b1 100644 (file)
--- a/NEWS.ja
+++ b/NEWS.ja
@@ -12,6 +12,10 @@ Yash 2.50
 
   *  terminfo データベースで何らかのキーが空文字列に対応させられて
      いても行編集がフリーズしないようにした
+  .  初期化スクリプト (yashrc) のサンプルを更新:
+    +  "crontab" コマンドのラッパー関数を追加し、"crontab -e" と打とう
+       としたときに誤って "crontab -r" でデータを消してしまうのを防ぐ
+       ようにした
   .  補完スクリプトを更新:
     +  git-rebase: Git 2.24.0 までの新しいオプションに対応
 
index 34e2044..15e1ee5 100644 (file)
@@ -138,6 +138,26 @@ if command --identify vim >/dev/null 2>&1; then
 
 fi
 
+# avoid removing existing crontab by accident
+crontab()
+if [ -t 0 ] && (
+  for arg do
+    case "${arg}" in
+      (-*r*) exit;;
+    esac
+  done
+  false
+) then
+  printf 'crontab: seems you are trying to clear your crontab.\n' >&2
+  printf 'are you sure? (yes/no) ' >&2
+  case "$(head -n 1)" in
+    ([Yy]*) command crontab "$@";;
+    (*)     printf 'crontab: cancelled.\n' >&2;;
+  esac
+else
+  command crontab "$@"
+fi
+
 # an alias that opens a file
 if command --identify xdg-open >/dev/null 2>&1; then
   alias o='xdg-open'