From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Philip K." Newsgroups: gmane.emacs.devel Subject: Re: [ELPA] New package: shell-command+ Date: Fri, 25 Sep 2020 15:52:22 +0200 Message-ID: <87zh5e0xrd.fsf@posteo.net> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18405"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 25 15:57:34 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kLoE9-0004fB-98 for ged-emacs-devel@m.gmane-mx.org; Fri, 25 Sep 2020 15:57:33 +0200 Original-Received: from localhost ([::1]:34454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLoE8-0005A6-BF for ged-emacs-devel@m.gmane-mx.org; Fri, 25 Sep 2020 09:57:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLo9P-0007H4-A1 for emacs-devel@gnu.org; Fri, 25 Sep 2020 09:52:39 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:60624) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLo9F-0001CR-GB for emacs-devel@gnu.org; Fri, 25 Sep 2020 09:52:37 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 7F2E7160062 for ; Fri, 25 Sep 2020 15:52:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1601041946; bh=aeNYJ6HLViQAMrWJedfimh426U5OWTDqHaxfbyn6BtQ=; h=From:To:Cc:Subject:Date:From; b=mBhzK67VXnMPAjyUmdZ5uPEWuO9e5azYHfOsVIDkT2es7mOmkFocqajCH+hVit0oC YE7ra0K1feDxNRQX1wrQHB6Z+Pm1QWZUtXBtkcRjmV8GO+xylmGhBUR2uA6dQNMPF9 r3ja1igzbitR3ndOL8MI+ayZCeZpbQhL38WCoCnQSfNKs47eJbTcqFlHAdhe2PXdmN JWDbkpDnuKSAFMp2wdSFwWOn+eknEKQaaAw0Ts8kOl+sIT3Wtq/BxALLLp/78mHh+/ WfrDOPa83cppTudkOhYvAzUd/IMFyXExRD58zu+pFVdyAZxGQa3fhdlqSIAxjX5Ssx pD10BxwokC5HA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4ByYJ961tfz6tmP; Fri, 25 Sep 2020 15:52:25 +0200 (CEST) In-Reply-To: (message from Stefan Monnier on Fri, 25 Sep 2020 09:43:57 -0400) Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/25 08:56:20 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:256430 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier writes: >> I wanted to submit this package I wrote a while ago. It provides an >> interactive command named "shell-command+", that is used in the same way >> as one uses shell-command. > > Sounds good. Do you have a pointer to the code? Oh, I forgot to attach it: --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=shell-command+.el ;;; shell-command+.el --- An extended shell-command -*- lexical-binding: t -*- ;; Author: Philip K. ;; Version: 1.0.3 ;; Keywords: unix, processes, convenience ;; Package-Requires: ((emacs "24.1")) ;; URL: http://elpa.gnu.org/packages/shell-command+.html ;; This file is NOT part of Emacs. ;; ;; This file is in the public domain, to the extent possible under law, ;; published under the CC0 1.0 Universal license. ;; ;; For a full copy of the CC0 license see ;; https://creativecommons.org/publicdomain/zero/1.0/legalcode ;;; Commentary: ;; ;; `shell-command+' is a `shell-command' substitute, that extends the ;; regular Emacs command with several features. ;; ;; A few examples of what `shell-command+' can do: ;; ;; ;; > wc -l ;; ;; Count all lines in a buffer, and display the result in the ;; minibuffer. ;; ;; ;; .. < ls -l ;; ;; Replace the current region (or buffer in no region is selected) ;; with a directory listing of the parent directory. ;; ;; ;; | tr -d a-z ;; ;; Delete all instances of the charachters a, b, c, ..., z, in the ;; selected region (or buffer, if no region was selected). ;; ;; ;; ... make ;; ;; Run Eshell's make (i.e. `compile') in the parent's parent ;; directory. (eval-when-compile (require 'rx)) (require 'eshell) ;;; Code: (defgroup shell-command+ nil "An extended `shell-command'" :group 'external :prefix "shell-command+-") (defcustom shell-command+-use-eshell t "Check if there is an eshell-handler for each command." :type 'boolean) (defconst shell-command+--command-regexp (rx bos ;; ignore all preceding whitespace (* space) ;; check for working directory string (? (group (or (: ?. (not (any "/"))) ?/ ?~) (* (not space))) (+ space)) ;; check for redirection indicator (? (or (group ?<) (group ?>) (group ?|) ?!)) ;; allow whitespace after indicator (* space) ;; actual command (and command name) (group (: (group (*? not-newline)) (? space)) (+ not-newline)) eos) "Regular expression to parse `shell-command+' input.") (defun shell-command+-expand-path (path) "Expand any PATH into absolute path with additional tricks. Furthermore, replace each sequence with three or more `.'s with a proper upwards directory pointers. This means that '....' becomes '../../../..', and so on." (expand-file-name (replace-regexp-in-string (rx (>= 2 ".")) (lambda (sub) (mapconcat #'identity (make-list (1- (length sub)) "..") "/")) path))) ;;;###autoload (defun shell-command+ (command beg end) "Intelligently execute string COMMAND in inferior shell. If COMMAND is prefixed with an absolute or relative path, the created process will the executed in the specified path. When COMMAND starts with... < the output of COMMAND replaces the current selection > COMMAND is run with the current selection as input | the current selection is filtered through COMMAND ! COMMAND is simply executed (same as without any prefix) If `shell-command+-use-eshell' is non-nil, and the the first argument of COMMAND has a defined `eshell'-function, use that. Inside COMMAND, % is replaced with the current file name. To insert a literal % quote it using a backslash. These extentions can all be combined with one-another. In case a region is active, `shell-command+' will only work with the region between BEG and END. Otherwise the whole buffer is processed." (interactive (list (read-shell-command "Shell command: ") (if (use-region-p) (region-beginning) (point-min)) (if (use-region-p) (region-end) (point-max)))) (save-match-data (unless (string-match shell-command+--command-regexp command) (error "Invalid command")) (let ((path (match-string-no-properties 1 command)) (cmd (match-string-no-properties 6 command)) (rest (condition-case nil (replace-regexp-in-string (rx (* ?\\ ?\\) (or ?\\ (group "%"))) buffer-file-name (match-string-no-properties 5 command) nil nil 1) (error (match-string-no-properties 5 command))))) (let ((default-directory (shell-command+-expand-path (or path ".")))) (cond ((match-string-no-properties 2 command) ;< (delete-region beg end) (shell-command rest t shell-command-default-error-buffer) (exchange-point-and-mark)) ((match-string-no-properties 3 command) ;> (shell-command-on-region beg end rest nil nil shell-command-default-error-buffer t)) ((match-string-no-properties 4 command) ;| (shell-command-on-region beg end rest t t shell-command-default-error-buffer t)) ((and shell-command+-use-eshell (intern-soft (concat "eshell/" cmd))) (eshell-command rest (and current-prefix-arg t))) (t (shell-command rest (and current-prefix-arg t) shell-command-default-error-buffer))))))) (provide 'shell-command+) ;;; shell-command+.el ends here --=-=-= Content-Type: text/plain > I don't see your name in the list of people with copyright assignments. > Then again, I do see some "Philip K..." but I can't be sure it's > indeed you. Did you sign the paperwork already? Yes, I signed it last year when my address was philip@warpmail.net. >> It should also be noted, that the file is currently licensed under the >> CC0 1.0 Universal (CC0 1.0) Public Domain Dedication[1] license, which >> I'm not sure if it is OK. > > That's not a problem for us, but we'd change it to GPLv3+ when we add it > to GNU ELPA. Not sure if that would be OK with you. No problem with that. -- Philip K. --=-=-=--