From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ergus Newsgroups: gmane.emacs.devel Subject: Re: [ELPA] New package: shell-command+ Date: Sat, 26 Sep 2020 01:38:18 +0200 Message-ID: <20200925233818.qtshrgoyjesg547h@Ergus> References: <87zh5e0xrd.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39247"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier , emacs-devel@gnu.org To: "Philip K." Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Sep 26 01:39:47 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 1kLxJa-000A50-RN for ged-emacs-devel@m.gmane-mx.org; Sat, 26 Sep 2020 01:39:46 +0200 Original-Received: from localhost ([::1]:58814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLxJZ-0005eD-TQ for ged-emacs-devel@m.gmane-mx.org; Fri, 25 Sep 2020 19:39:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLxIS-0005AJ-7i for emacs-devel@gnu.org; Fri, 25 Sep 2020 19:38:38 -0400 Original-Received: from sonic304-10.consmr.mail.bf2.yahoo.com ([74.6.128.33]:44798) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLxIO-0000ZH-9I for emacs-devel@gnu.org; Fri, 25 Sep 2020 19:38:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1601077109; bh=cUHnZOB1Dx6+MVpMwaTP2lBs2RGBdmSImBpELPtffAg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=pSYZ1uc1EfScE8W6FBSbEeXUybhPQP/orfApE/XybeM/TlX8i+O4DtNYKUig+AZj4n2sklVi0Tb1aYmPS9JmPd7W7VuPH8Vx9qpIMitUKmi2WMC08R0MMRcHoGltM5bF6ptHOGSj20LsHq9aCY+F8gX60Ha/fCsYhnXdRgLrl7ogOIAEkGYm7AIxkoP3R21k0dGCsYUSA+pLLE1xMHqc5noXryDPA+ZVsZLcQr3czzucQDfqGVolb6LigMiZAnd+Hu7MNlopSaYmIPUgypXv/q2SLU1R/lGXR1ZdA3G1emfNVQhVNJ3Do90SU2PbC58ZirlFGlbn7Nbo3IShv3vcJQ== X-YMail-OSG: Bfcm6nYVM1mEKV4FobZ4vIVKGndYjE7.SEe_RyITiIzQyjnQLbR1stPNYZRyYfR fdih1gb.n4_9sPr3yFn_Kg0mTejcY4cMwDNONv.ifi.XeS5cRX6BWIInF9biq4QA6SuhqU0zn9Xz xIIXpYqnPVKwc14AvMHGnUAcsE55E0RTXWhSV_P_vONHNQw9I149T9DqwHOOCJ88k.4TCy9gR95R _AAIgT_T6kYqQPhViXB3BqqWgHq6KnQmaX0IjOj8nrY_WvvyZLf4L1L_4_BD.bQ0Jj8c7wc5kDXN Our9aO8Kd70clTyEh1_G.0funYitJ3GvpU.ItpIYErufk4GH2XGs7dYnZ15bUsA6ZyfZWfQ8i81t OBiCmHVgla_hnWAjy8c4W881S94czTltLcgj.ivAYm1mbCVzhY1RxsVy1uPukTUJNlZ_BflGosWE GzLwp36zNNkunK_nIJGmEM.ceS3nZ7rzyfcL5HAHCzqotM9ihr6FhhCHZhThAH9KN1JDYNi3pN6k sIbMjo.BW3oleTadEAOWeE037NZyor_7A_y4Vv8W1sofSYE3JwX5SUy_OPkp49axJGcEU3zkYNdz 2V9EPbLlk8IppHo2uXseRiDQWWjBxDqt_OAsUIf6Kzrh0vqo2LPvkgrMn1cOwvpgUQbVfouyJaQy RpR4P3Dg2lDXT4z9jTFCPmdpJNfd2UMjky.4NqiDpuHpfe7VNPebCHjzuCnUyC6665rYt8OwD1_G JERjMccFiK.wtS8OYyvV5elWqjHuFxH2g3O3_E9n221.WxCcufncbNMr5XeMjPE3E0oEDRaqoEf_ xiTbq5uKYqTIhJ5Vxqr4dCHGNcUbjZ6Fc3wy86nEnm Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.bf2.yahoo.com with HTTP; Fri, 25 Sep 2020 23:38:29 +0000 Original-Received: by smtp406.mail.ir2.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID a41b696a1ab8816dce59b549dfd23339; Fri, 25 Sep 2020 23:38:28 +0000 (UTC) Content-Disposition: inline In-Reply-To: <87zh5e0xrd.fsf@posteo.net> X-Mailer: WebService/1.1.16674 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol Apache-HttpAsyncClient/4.1.4 (Java/11.0.7) Received-SPF: pass client-ip=74.6.128.33; envelope-from=spacibba@aol.com; helo=sonic304-10.consmr.mail.bf2.yahoo.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/25 19:38:29 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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:256439 Archived-At: Hi Philip: As a long time Bang user I am happy to see it in Elpa. May I suggest (in spite of it is very simple) you to add the configuration lines in the Readme and package description for new users? If you want to add also the use-package config I have this in my init file too: (use-package bang :ensure t :bind ("M-!" . bang)) Best, Ergus On Fri, Sep 25, 2020 at 03:52:22PM +0200, Philip K. wrote: >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: > >;;; 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 > >> 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.