From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10805 invoked by alias); 14 Sep 2011 22:46:57 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16355 Received: (qmail 29077 invoked from network); 14 Sep 2011 22:46:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.216.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; bh=M/MUvf97qZZ+YJ0rWujUVErD3VOTVnpWlvrqO8hXj9g=; b=MFrIR6t5Cb7pEpN0T2bazmwbSuZ0aw3N9KenO5IM6NlAc+l0+Ls1G1qXuqUMDW2F3P /e7jCZ5RYEoAWzaV9TCxPGcc7ZCpXNHAini4in1XB58nxRnrkTUz+bPu3IdpeFHzXD1e A7XT5JIb9BDr54fGUuFLzhWR7aX7KCiCgFNTM= MIME-Version: 1.0 From: TJ Luoma Date: Wed, 14 Sep 2011 18:19:26 -0400 Message-ID: Subject: add 'sudo' to 'mv' if file isn't writable by $USER To: Zsh Users Content-Type: text/plain; charset=ISO-8859-1 I'm wondering if someone has already done this. I have a function which does this: move () { command which -s gmv if [ "$?" = "0" ] then gmv --verbose --backup=numbered $@ else mv -v -i $@ fi } (simply put: use 'gmv' if it exists, otherwise use 'mv') That works pretty well (although if there are ways to do it better, please let me know). HOWEVER, now I want to do "If $FILE is writable by $USER, do 'move' as above. ELSE use 'sudo' before the mv or gmv command" I can probably cobble together a solution, but I thought I'd check first to see if someone here had already invented this wheel. TjL