2019-12-30 07:14:26 +00:00
|
|
|
;;; quiet.el --- Disconnect from the online world for a while
|
2016-05-06 12:33:46 +00:00
|
|
|
|
|
|
|
;; Copyright 2016 FoAM vzw
|
|
|
|
;;
|
|
|
|
;; Author: nik gaffney <nik@fo.am>
|
|
|
|
;; Created: 2016-05-05
|
|
|
|
;; Version: 0.1
|
2019-12-30 07:14:26 +00:00
|
|
|
;; Keywords: convenience, quiet, distraction, network, detachment, offline
|
|
|
|
;; URL: https://github.com/zzkt/quiet
|
2016-05-06 12:33:46 +00:00
|
|
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2020-02-11 07:21:42 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
2016-05-06 12:33:46 +00:00
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
2020-02-11 07:21:42 +00:00
|
|
|
|
2016-05-06 12:33:46 +00:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
2020-02-11 07:21:42 +00:00
|
|
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2016-05-06 12:33:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
2016-05-08 10:26:24 +00:00
|
|
|
;; A simple package to disconnect from the online world for a while,
|
2019-12-30 07:14:26 +00:00
|
|
|
;; possibly reconnecting later. Any interruptions or distractions
|
2016-05-08 10:26:24 +00:00
|
|
|
;; which occur once the command is run are guaranteed to be local.
|
2016-05-06 12:33:46 +00:00
|
|
|
;;
|
2016-05-08 10:26:24 +00:00
|
|
|
;; 'M-x quiet' will disconnect from the network, optionally
|
|
|
|
;; reconnecting after a certain time.
|
|
|
|
;;
|
2019-12-30 07:14:26 +00:00
|
|
|
;; the function 'quiet' can be used anywhere in Emacs where a lack of
|
2016-05-08 10:26:24 +00:00
|
|
|
;; network access could be seen as a feature, e.g. as a mode-hook (or
|
|
|
|
;; with defadvice) to your preferred distraction free writing
|
|
|
|
;; environment.
|
|
|
|
;;
|
|
|
|
;; you may need to customize or setq quiet-disconnect and
|
|
|
|
;; quiet-connect to the appropriate shell commands to turn your
|
|
|
|
;; network (interface) on or off
|
2016-05-06 12:33:46 +00:00
|
|
|
;;
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
2023-05-30 08:59:12 +00:00
|
|
|
(defcustom quiet-disconnect "networksetup -setairportpower airport off"
|
2019-12-30 07:14:26 +00:00
|
|
|
"Shell command to turn off network connection(s)."
|
2023-05-30 08:59:12 +00:00
|
|
|
:type '(choice
|
|
|
|
(string :tag "macOS" "networksetup -setairportpower airport off")
|
|
|
|
(string :tag "GNU/Linux" "ifdown wlan0")
|
|
|
|
(string :tag "*BSD" "ifdown wlan0")
|
|
|
|
(string :tag "other" ""))
|
2016-05-06 12:33:46 +00:00
|
|
|
:group 'quiet)
|
|
|
|
|
2023-05-30 08:59:12 +00:00
|
|
|
(defcustom quiet-connect "networksetup -setairportpower airport on"
|
2019-12-30 07:14:26 +00:00
|
|
|
"Shell command to turn on network connection(s)."
|
2023-05-30 08:59:12 +00:00
|
|
|
:type '(choice
|
|
|
|
(string :tag "macOS" "networksetup -setairportpower airport on")
|
|
|
|
(string :tag "GNU/Linux" "ifup wlan0")
|
|
|
|
(string :tag "*BSD" "ifup wlan0")
|
|
|
|
(string :tag "other" ""))
|
|
|
|
:group 'quiet)
|
|
|
|
|
|
|
|
(defcustom quiet-timer 0
|
|
|
|
"Timer to reconnect network after a given time (in minutes).
|
|
|
|
A value of 0 will leave the connection off."
|
2016-05-06 12:33:46 +00:00
|
|
|
:type 'integer
|
|
|
|
:group 'quiet)
|
|
|
|
|
2016-05-08 12:56:16 +00:00
|
|
|
;;;###autoload
|
2016-05-06 12:33:46 +00:00
|
|
|
(defun quiet ()
|
2019-12-30 07:14:26 +00:00
|
|
|
"Quieten network distractions for a while..."
|
2016-05-06 12:33:46 +00:00
|
|
|
(interactive)
|
|
|
|
(save-window-excursion
|
2023-05-30 08:59:12 +00:00
|
|
|
(message "disconnecting...")
|
|
|
|
(async-shell-command quiet-disconnect))
|
2016-05-06 12:33:46 +00:00
|
|
|
(if (not (= quiet-timer 0))
|
2019-12-30 07:14:26 +00:00
|
|
|
(progn
|
2023-05-30 08:59:12 +00:00
|
|
|
(run-at-time (* quiet-timer 60) nil 'quiet-reconnect))))
|
2016-05-06 12:33:46 +00:00
|
|
|
|
2019-12-30 07:14:26 +00:00
|
|
|
;; provide a 'disconnect' alias
|
|
|
|
(fset 'disconnect 'quiet)
|
|
|
|
|
2016-05-08 12:56:16 +00:00
|
|
|
;;;###autoload
|
2016-05-06 12:33:46 +00:00
|
|
|
(defun quiet-reconnect ()
|
2019-12-30 07:14:26 +00:00
|
|
|
"Reconnect to networked distractions."
|
2016-05-06 12:33:46 +00:00
|
|
|
(interactive)
|
|
|
|
(save-window-excursion
|
2023-05-30 08:59:12 +00:00
|
|
|
(message "reconnecting after ~%d %s"
|
|
|
|
quiet-timer
|
|
|
|
(if (= quiet-timer 1) "minute" "minutes"))
|
|
|
|
(async-shell-command quiet-connect)))
|
2016-05-06 12:33:46 +00:00
|
|
|
|
2016-05-08 12:56:16 +00:00
|
|
|
(provide 'quiet)
|
|
|
|
|
2016-05-06 12:33:46 +00:00
|
|
|
;;; quiet.el ends here
|