|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
"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. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Henry Townsend wrote:
>the file exists and is readable at its named location, Or, arguably, writable. |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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 *** |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
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 *** |
|
![]() |
| Outils de la discussion | |
|
|