PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > useful shell shortcuts
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

useful shell shortcuts

Réponse
 
LinkBack Outils de la discussion
Vieux 06/12/2006, 16h19   #1
Henry Townsend
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut useful shell shortcuts

There are two features I've often wished for in my shell (ksh) and am
wondering if any other shell has them.

(1) Due to finger-fumbles I often type just "/some/dir" when I meant
'cd /some/dir" or "pushd /some/dir", which results in the error message
"/some/dir: cannot execute". Since the idea of executing a directory is
clearly preposterous, why can't the shell interpret this as a cd (or
pushd) request?

(2) Similarly, I sometimes type "file" instead of "vi file". But why
can't the shell be configurable to run "$EDITOR file" in that case iff
the file exists as named? Yes, it does have an icky Windows-ish feeling
but that doesn't mean it couldn't be useful. This one I've sort-of
implemented with a "trap ... ERR" hack in the past but it wasn't ideal
for reasons I no longer remember.

Of course either of these could be configurable by a "set -o" flag. So:
do any shells (bash, zsh, etc) offer these and if not, what's the
argument against them?

Thanks,
HT
  Réponse avec citation
Vieux 06/12/2006, 16h59   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: useful shell shortcuts

2006-12-06, 11:19(-05), Henry Townsend:
> There are two features I've often wished for in my shell (ksh) and am
> wondering if any other shell has them.
>
> (1) Due to finger-fumbles I often type just "/some/dir" when I meant
> 'cd /some/dir" or "pushd /some/dir", which results in the error message
> "/some/dir: cannot execute". Since the idea of executing a directory is
> clearly preposterous, why can't the shell interpret this as a cd (or
> pushd) request?


zsh can do that.

setopt autocd autopushd

AUTO_CD (-J)
If a command is issued that can't be executed as a normal command,
and the command is the name of a directory, perform the cd command
to that directory.

AUTO_PUSHD (-N)
Make cd push the old directory onto the directory stack.


> (2) Similarly, I sometimes type "file" instead of "vi file". But why
> can't the shell be configurable to run "$EDITOR file" in that case iff
> the file exists as named? Yes, it does have an icky Windows-ish feeling
> but that doesn't mean it couldn't be useful. This one I've sort-of
> implemented with a "trap ... ERR" hack in the past but it wasn't ideal
> for reasons I no longer remember.

[...]

I wouldn't do that, as it could be dangerous.

But it's possible with zsh as well

alias -s pdf=acroread
alias -s c=vi

runs acroread for pdf files and vi for c files.

You can also add a trap on ZERR or use a TRAPZERR function (some
systems have SIGERR signal, hence ZERR instead of ERR).

--
Stéphane
  Réponse avec citation
Vieux 06/12/2006, 18h44   #3
Tintin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: useful shell shortcuts


"Henry Townsend" <henry.townsend@not.here> wrote in message
news:84SdnSHoou0pcOvYnZ2dnUVZ_oidnZ2d@comcast.com. ..
> There are two features I've often wished for in my shell (ksh) and am
> wondering if any other shell has them.
> (2) Similarly, I sometimes type "file" instead of "vi file". But why can't
> the shell be configurable to run "$EDITOR file" in that case iff the file
> exists as named? Yes, it does have an icky Windows-ish feeling but that
> doesn't mean it couldn't be useful. This one I've sort-of implemented with
> a "trap ... ERR" hack in the past but it wasn't ideal for reasons I no
> longer remember.


What if file is an executable that you want to run, or were you only
refererring to files without execute permission set?



--
Posted via a free Usenet account from http://www.teranews.com

  Réponse avec citation
Vieux 07/12/2006, 01h55   #4
Bruce Barnett
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: useful shell shortcuts

"Tintin" <tintin@invalid.invalid> writes:

> "Henry Townsend" <henry.townsend@not.here> wrote in message
> news:84SdnSHoou0pcOvYnZ2dnUVZ_oidnZ2d@comcast.com. ..
>> There are two features I've often wished for in my shell (ksh) and am
>> wondering if any other shell has them.
>> (2) Similarly, I sometimes type "file" instead of "vi file". But why can't
>> the shell be configurable to run "$EDITOR file" in that case iff the file
>> exists as named? Yes, it does have an icky Windows-ish feeling but that
>> doesn't mean it couldn't be useful. This one I've sort-of implemented with
>> a "trap ... ERR" hack in the past but it wasn't ideal for reasons I no
>> longer remember.

>
> What if file is an executable that you want to run, or were you only
> refererring to files without execute permission set?



And what if you want to edit a file that was the name of a command?
Or edit a file with the name of your editor?

Or the file is 2GB, and calling up the editor causes the system to
s l o o w d o o o n.



--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
  Réponse avec citation
Vieux 07/12/2006, 02h35   #5
Henry Townsend
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: useful shell shortcuts

Tintin wrote:
> "Henry Townsend" <henry.townsend@not.here> wrote in message
> news:84SdnSHoou0pcOvYnZ2dnUVZ_oidnZ2d@comcast.com. ..
>> There are two features I've often wished for in my shell (ksh) and am
>> wondering if any other shell has them.
>> (2) Similarly, I sometimes type "file" instead of "vi file". But why can't
>> the shell be configurable to run "$EDITOR file" in that case iff the file
>> exists as named? Yes, it does have an icky Windows-ish feeling but that
>> doesn't mean it couldn't be useful. This one I've sort-of implemented with
>> a "trap ... ERR" hack in the past but it wasn't ideal for reasons I no
>> longer remember.

>
> What if file is an executable that you want to run, or were you only
> refererring to files without execute permission set?


Well, in my case I *never* have "." in PATH and thus would never type
"command" expecting ./command to be run. But yes, I should have made it
clearer; I'd expect the shell to invoke $EDITOR iff (a) the exec search
failed and (b) the file exists and is readable at its named location,
i.e. access(file, F_OK) succeeds.
  Réponse avec citation
Vieux 07/12/2006, 02h57   #6
Henry Townsend
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: useful shell shortcuts

Bruce Barnett wrote:
> And what if you want to edit a file that was the name of a command?
> Or edit a file with the name of your editor?


Addressed in parallel response.

> Or the file is 2GB, and calling up the editor causes the system to
> s l o o w d o o o n.


Two answers:

1. Ctrl-C.

2. I did say it should be configurable. Every option comes with a reason
someone might not want it; that's why it's an option.

HT
  Réponse avec citation
Vieux 07/12/2006, 02h58   #7
Henry Townsend
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: useful shell shortcuts

Henry Townsend wrote:
>the file exists and is readable at its named location,


Or, arguably, writable.
  Réponse avec citation
Vieux 07/12/2006, 04h45   #8
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: useful shell shortcuts

In article <84SdnSHoou0pcOvYnZ2dnUVZ_oidnZ2d@comcast.com>,
Henry Townsend <henry.townsend@not.here> wrote:

> There are two features I've often wished for in my shell (ksh) and am
> wondering if any other shell has them.
>
> (1) Due to finger-fumbles I often type just "/some/dir" when I meant
> 'cd /some/dir" or "pushd /some/dir", which results in the error message
> "/some/dir: cannot execute". Since the idea of executing a directory is
> clearly preposterous, why can't the shell interpret this as a cd (or
> pushd) request?


It's also likely that this was a typo for

/some/dir/filename

>
> (2) Similarly, I sometimes type "file" instead of "vi file". But why
> can't the shell be configurable to run "$EDITOR file" in that case iff
> the file exists as named? Yes, it does have an icky Windows-ish feeling
> but that doesn't mean it couldn't be useful. This one I've sort-of
> implemented with a "trap ... ERR" hack in the past but it wasn't ideal
> for reasons I no longer remember.


How long have you been using Unix? I ask this because I think that
after a while these commands become second nature. I expect that it's
only when you're first starting that you make silly mistakes like this,
and these shortcuts would just perpetuate the bad habits.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
  Réponse avec citation
Vieux 07/12/2006, 12h05   #9
Henry Townsend
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: useful shell shortcuts

Barry Margolin wrote:
> It's also likely that this was a typo for
>
> /some/dir/filename


Yes. Sorry.

> How long have you been using Unix? I ask this because I think that
> after a while these commands become second nature. I expect that it's
> only when you're first starting that you make silly mistakes like this,
> and these shortcuts would just perpetuate the bad habits.


It's not a matter of familiarity but one of typing. I'm a terrible
typist, which means I'm a heavy user of command-line editing, and
somehow my fingers tend to fumble and I mangle a line in the ways described.

HT
  Réponse avec citation
Vieux 07/12/2006, 12h55   #10
Bruce Barnett
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: useful shell shortcuts

Henry Townsend <henry.townsend@not.here> writes:

> It's not a matter of familiarity but one of typing. I'm a terrible
> typist, which means I'm a heavy user of command-line editing, and
> somehow my fingers tend to fumble and I mangle a line in the ways
> described.


I tend to create aliases/functions/symbolic links and
shortcuts to make my life easier.

So if I want to go to a /some/place/far/away/directory a short 1, 2 or 3
letter command will do so.


But I prefer some predictability and dislike surprises when I make a
typing error. For instance, suppose I dropped a character, unknowingly
changed directory, and executed a program I did not want to execute.
If I ran the production version versus a test version - it could have
nasty consequences.

Or if a command is modal - where it behaves differently
based on the state of some external object. I wouldn't personally like that.

But if you want to - fine.

It would be easy to make up a single character command that checks the
argument and does different things based on the type of argument.

If a directory - go to it
if a text file - edit it
If an executable - based on the name/table
run it in the background
run it immediately
run it in a new window




--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.
  Réponse avec citation
Vieux 07/12/2006, 14h16   #11
Gandalf Parker
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: useful shell shortcuts

Henry Townsend <henry.townsend@not.here> contributed wisdom to
news:84SdnSHoou0pcOvYnZ2dnUVZ_oidnZ2d@comcast.com:

> There are two features I've often wished for in my shell (ksh) and am
> wondering if any other shell has them.
>
> (1) Due to finger-fumbles I often type just "/some/dir" when I meant
> 'cd /some/dir" or "pushd /some/dir", which results in the error message
> "/some/dir: cannot execute". Since the idea of executing a directory is
> clearly preposterous, why can't the shell interpret this as a cd (or
> pushd) request?


It would be abit hard for the system to tell. So each command line needs
to know that you werent preceding a directory to a command or checking
for existence of a file vs directory. Or maybe the error could catch it.
That would take care of the first example anyway.

> (2) Similarly, I sometimes type "file" instead of "vi file". But why
> can't the shell be configurable to run "$EDITOR file" in that case iff
> the file exists as named? Yes, it does have an icky Windows-ish feeling
> but that doesn't mean it couldn't be useful. This one I've sort-of
> implemented with a "trap ... ERR" hack in the past but it wasn't ideal
> for reasons I no longer remember.


Default file handlers like Windows has? That allows some of the invasion
techniques that windows has problems with. Is this worth that?

Gandalf Parker
  Réponse avec citation
Vieux 07/12/2006, 14h47   #12
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: useful shell shortcuts

2006-12-07, 07:05(-05), Henry Townsend:
> Barry Margolin wrote:
>> It's also likely that this was a typo for
>>
>> /some/dir/filename

>
> Yes. Sorry.
>
>> How long have you been using Unix? I ask this because I think that
>> after a while these commands become second nature. I expect that it's
>> only when you're first starting that you make silly mistakes like this,
>> and these shortcuts would just perpetuate the bad habits.

>
> It's not a matter of familiarity but one of typing. I'm a terrible
> typist, which means I'm a heavy user of command-line editing, and
> somehow my fingers tend to fumble and I mangle a line in the ways described.

[...]

In addition to you two requests, zsh can also suggest (or
immediately correct) corrections to what you type.

That's part of the completion system.

If you type:

vi /etc/pasw<Tab>

zsh can propose you to complete that to /etc/passwd.

Run:

autoload compinstall
compinstall

one of the menus is about approximate completion.

--
Stéphane
  Réponse avec citation
Vieux 08/12/2006, 02h45   #13
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: useful shell shortcuts

In article <GOydnWSwF5jsnuXYnZ2dnUVZ_qadnZ2d@comcast.com>,
Henry Townsend <henry.townsend@not.here> wrote:

> Barry Margolin wrote:
> > It's also likely that this was a typo for
> >
> > /some/dir/filename

>
> Yes. Sorry.
>
> > How long have you been using Unix? I ask this because I think that
> > after a while these commands become second nature. I expect that it's
> > only when you're first starting that you make silly mistakes like this,
> > and these shortcuts would just perpetuate the bad habits.

>
> It's not a matter of familiarity but one of typing. I'm a terrible
> typist, which means I'm a heavy user of command-line editing, and
> somehow my fingers tend to fumble and I mangle a line in the ways described.


Maybe I'm wrong, but my theory is that even a bad typist will develop
habits from the commands they type frequently, and you're much less
likely to make typoes in these habitual sequences.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h55.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,26474 seconds with 21 queries