zsh-users
 help / color / mirror / code / Atom feed
From: TJ Luoma <luomat@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: add 'sudo' to 'mv' if file isn't writable by $USER
Date: Wed, 14 Sep 2011 18:19:26 -0400	[thread overview]
Message-ID: <CADjGqHtVg9bnFTHE2gk59m3cnnLsWJjzYAgr9V4=gioPbxPnHg@mail.gmail.com> (raw)

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


             reply	other threads:[~2011-09-14 22:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-14 22:19 TJ Luoma [this message]
2011-09-15  3:30 ` Benjamin R. Haskell
2011-09-15 18:20   ` TJ Luoma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADjGqHtVg9bnFTHE2gk59m3cnnLsWJjzYAgr9V4=gioPbxPnHg@mail.gmail.com' \
    --to=luomat@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).