* Bash Script Editing Mode?
@ 2008-08-07 20:21 formido
2008-08-07 20:49 ` Mike Treseler
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: formido @ 2008-08-07 20:21 UTC (permalink / raw
To: help-gnu-emacs
There's a shell mode, but it has a prompt and doesn't help you
incrementally create a shell script as efficiently as it could, unless
I'm missing something. Is there any shell script mode that works more
like the elisp, python, or erlang repls, where you can execute your
choice of several lines at once and you can go back and edit and
execute the lines in situ? If I write a bash function, editing and
reloading the function is a painful process. I'm looking for something
a little bit like the Mac's BBEdit shell worksheets (only better).
I considered altering the usual shell mode, but it would take more
than slight edits, so I'm hoping something's already out there. For
example, one should be able to go back to a function, tweak it, and
reload with a minimum of keyboard fuss.
Michael
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash Script Editing Mode?
2008-08-07 20:21 Bash Script Editing Mode? formido
@ 2008-08-07 20:49 ` Mike Treseler
2008-08-07 22:10 ` formido
2008-08-07 20:53 ` Lennart Borgman (gmail)
` (4 subsequent siblings)
5 siblings, 1 reply; 9+ messages in thread
From: Mike Treseler @ 2008-08-07 20:49 UTC (permalink / raw
To: help-gnu-emacs
formido wrote:
> Is there any shell script mode that works more
> like the elisp, python, or erlang repls, where you can execute your
> choice of several lines at once and you can go back and edit and
> execute the lines in situ? If I write a bash function, editing and
> reloading the function is a painful process. I'm looking for something
> a little bit like the Mac's BBEdit shell worksheets (only better).
>
> I considered altering the usual shell mode, but it would take more
> than slight edits, so I'm hoping something's already out there. For
> example, one should be able to go back to a function, tweak it, and
> reload with a minimum of keyboard fuss.
>
> Michael
This looks interesting:
http://bashdb.sourceforge.net/bashdb.html#SEC2
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash Script Editing Mode?
2008-08-07 20:21 Bash Script Editing Mode? formido
2008-08-07 20:49 ` Mike Treseler
@ 2008-08-07 20:53 ` Lennart Borgman (gmail)
2008-08-07 21:06 ` Thierry Volpiatto
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Lennart Borgman (gmail) @ 2008-08-07 20:53 UTC (permalink / raw
To: formido; +Cc: help-gnu-emacs
formido wrote:
> There's a shell mode, but it has a prompt and doesn't help you
> incrementally create a shell script as efficiently as it could, unless
> I'm missing something. Is there any shell script mode that works more
> like the elisp, python, or erlang repls, where you can execute your
> choice of several lines at once and you can go back and edit and
> execute the lines in situ? If I write a bash function, editing and
> reloading the function is a painful process. I'm looking for something
> a little bit like the Mac's BBEdit shell worksheets (only better).
>
> I considered altering the usual shell mode, but it would take more
> than slight edits, so I'm hoping something's already out there. For
> example, one should be able to go back to a function, tweak it, and
> reload with a minimum of keyboard fuss.
You can search for available commands from the help menu. Major modes
are commands so you can use the menu entry
Help
Search Documentation
Find Commands by Name
I guessed that such a major mode would match
^sh.*-mode$
and found some that might help you (I am not sure).
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash Script Editing Mode?
2008-08-07 20:21 Bash Script Editing Mode? formido
2008-08-07 20:49 ` Mike Treseler
2008-08-07 20:53 ` Lennart Borgman (gmail)
@ 2008-08-07 21:06 ` Thierry Volpiatto
2008-08-07 21:20 ` Pascal J. Bourguignon
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Thierry Volpiatto @ 2008-08-07 21:06 UTC (permalink / raw
To: formido; +Cc: help-gnu-emacs
formido <formido@gmail.com> writes:
> There's a shell mode, but it has a prompt and doesn't help you
> incrementally create a shell script as efficiently as it could, unless
> I'm missing something. Is there any shell script mode that works more
> like the elisp, python, or erlang repls, where you can execute your
> choice of several lines at once and you can go back and edit and
> execute the lines in situ? If I write a bash function, editing and
> reloading the function is a painful process. I'm looking for something
> a little bit like the Mac's BBEdit shell worksheets (only better).
>
> I considered altering the usual shell mode, but it would take more
> than slight edits, so I'm hoping something's already out there. For
> example, one should be able to go back to a function, tweak it, and
> reload with a minimum of keyboard fuss.
>
> Michael
>
May be that help:
,----[ C-h f shell-command-on-region RET ]
| shell-command-on-region is an interactive compiled Lisp function in
| `simple.el'.
|
| It is bound to M-|, <menu-bar> <tools> <shell-on-region>.
|
| (shell-command-on-region start end command &optional output-buffer
| replace error-buffer display-error-buffer)
|
| Execute string command in inferior shell with region as input.
| Normally display output (if any) in temp buffer `*Shell Command Output*';
| Prefix arg means replace the region with it. Return the exit code of
| command.
|
| To specify a coding system for converting non-ASCII characters
| in the input and output to the shell command, use C-x RET c
| before this command. By default, the input (from the current buffer)
| is encoded in the same coding system that will be used to save the file,
| `buffer-file-coding-system'. If the output is going to replace the region,
| then it is decoded from that same coding system.
|
| The noninteractive arguments are start, end, command,
| output-buffer, replace, error-buffer, and display-error-buffer.
| Noninteractive callers can specify coding systems by binding
| `coding-system-for-read' and `coding-system-for-write'.
|
| If the command generates output, the output may be displayed
| in the echo area or in a buffer.
| If the output is short enough to display in the echo area
| (determined by the variable `max-mini-window-height' if
| `resize-mini-windows' is non-nil), it is shown there. Otherwise
| it is displayed in the buffer `*Shell Command Output*'. The output
| is available in that buffer in both cases.
|
| If there is output and an error, a message about the error
| appears at the end of the output.
|
| If there is no output, or if output is inserted in the current buffer,
| then `*Shell Command Output*' is deleted.
|
| If the optional fourth argument output-buffer is non-nil,
| that says to put the output in some other buffer.
| If output-buffer is a buffer or buffer name, put the output there.
| If output-buffer is not a buffer and not nil,
| insert output in the current buffer.
| In either case, the output is inserted after point (leaving mark after it).
|
| If replace, the optional fifth argument, is non-nil, that means insert
| the output in place of text from start to end, putting point and mark
| around it.
|
| If optional sixth argument error-buffer is non-nil, it is a buffer
| or buffer name to which to direct the command's standard error output.
| If it is nil, error output is mingled with regular output.
| If display-error-buffer is non-nil, display the error buffer if there
| were any errors. (This is always t, interactively.)
| In an interactive call, the variable `shell-command-default-error-buffer'
| specifies the value of error-buffer.
|
| This function is advised.
|
| Before-advice `shell-command-on-region-with-completion':
| Defined in shell-command.el, to enable tab-completion of commands
| and dir/filenames within the input context. This advice also makes
| `shell-command-on-region' to use this current buffer as its input when
| a region is visible and inactive.
| Its prompt string is kept by `shell-command-on-region-prompt' and
| `shell-command-on-region-prompt-if-region-inactive'.
|
| [back]
`----
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash Script Editing Mode?
2008-08-07 20:21 Bash Script Editing Mode? formido
` (2 preceding siblings ...)
2008-08-07 21:06 ` Thierry Volpiatto
@ 2008-08-07 21:20 ` Pascal J. Bourguignon
2008-08-07 21:59 ` formido
[not found] ` <mailman.16033.1218143342.18990.help-gnu-emacs@gnu.org>
[not found] ` <mailman.16028.1218142452.18990.help-gnu-emacs@gnu.org>
5 siblings, 1 reply; 9+ messages in thread
From: Pascal J. Bourguignon @ 2008-08-07 21:20 UTC (permalink / raw
To: help-gnu-emacs
formido <formido@gmail.com> writes:
> There's a shell mode, but it has a prompt and doesn't help you
> incrementally create a shell script as efficiently as it could, unless
> I'm missing something. Is there any shell script mode that works more
> like the elisp, python, or erlang repls, where you can execute your
> choice of several lines at once and you can go back and edit and
> execute the lines in situ? If I write a bash function, editing and
> reloading the function is a painful process. I'm looking for something
> a little bit like the Mac's BBEdit shell worksheets (only better).
First, try to get your terminology straight. You want a
shell-script-mode that be more like shell-mode, not a shell-mode
that's a different shell-script-mode.
That is, when you type M-x shell RET, you get a buffer that is in the
shell-mode, where you can edit a shell command, and when you type RET,
you get it executed.
On the other hand, when you type C-x C-f ~/bin/new-script RET M-x
shell-script-mode RET yo uget a buffer that is in the
shell-script-mode, where you can edit a shell script, but indeed for
now, you cannot have them executed from here.
> I considered altering the usual shell mode, but it would take more
> than slight edits, so I'm hoping something's already out there. For
> example, one should be able to go back to a function, tweak it, and
> reload with a minimum of keyboard fuss.
Well, if you consider the shell mode, there's an easy way to get what
you want: just edit your commands, one by one, and type RET to try
them. When you're happy with the result, type: history RET and
copy-and-paste all the commands to a shell script buffer, add some
minor edits, including a #!/bin/bash on the first line, and voilà.
But really, I would rather start from the shell-script-mode. What is
missing, it's the parsing for shell-script "sexprs". That is, keys
such as C-M-f are still bound to forward-sexp that parses a lisp sexp
instead of a shell one. (The problem of course is that it's much
harder to parse a shell expression).
Anyways, you could implement some minimal parser. It'd need to know
about continuation lines, <<EOF ... EOF literal input, ( ... ), $(
... ), $(( ... )), { ... } with the syntax before for the function
declaration, and the syntax of the compound builtins such as if/fi,
case/esac, etc.
Once you have implemented a pair of functions forward-shell-expression
and backward-shell-expression, you can easily implement a function
such as eval-last-shell-expression:
(defun eval-last-shell-expression (point)
(interactiev "P")
(let ((start (progn (backward-shell-expression) (point)))
(end (progn (forward-shell-expression) (point))))
(comint-send-string (inferior-shell-proc)
(buffer-substring start end))
(comint-send-string (inferior-shell-proc) "\n")))
There remains only to bind these commands to C-M-f, C-M-b and C-x C-e.
But if you're as lazy as me, perhaps the best option would be to use
scsh. You get a shell, but it's really a scheme, and there is already
all you need to edit scheme scripts, and C-x C-e already works.
--
__Pascal Bourguignon__ http://www.informatimago.com/
PUBLIC NOTICE AS REQUIRED BY LAW: Any use of this product, in any
manner whatsoever, will increase the amount of disorder in the
universe. Although no liability is implied herein, the consumer is
warned that this process will ultimately lead to the heat death of
the universe.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash Script Editing Mode?
2008-08-07 21:20 ` Pascal J. Bourguignon
@ 2008-08-07 21:59 ` formido
0 siblings, 0 replies; 9+ messages in thread
From: formido @ 2008-08-07 21:59 UTC (permalink / raw
To: help-gnu-emacs
On Aug 7, 2:20 pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> formido <form...@gmail.com> writes:
> > There's a shell mode, but it has a prompt and doesn't help you
> > incrementally create a shell script as efficiently as it could, unless
> > I'm missing something. Is there any shell script mode that works more
> > like the elisp, python, or erlang repls, where you can execute your
> > choice of several lines at once and you can go back and edit and
> > execute the lines in situ? If I write a bash function, editing and
> > reloading the function is a painful process. I'm looking for something
> > a little bit like the Mac's BBEdit shell worksheets (only better).
>
> First, try to get your terminology straight.
Heh. I've noticed that no matter with what care one designs his query,
a novice will invariably run afoul of the idioms or conventions of the
new culture...
<snip>
> > I considered altering the usual shell mode, but it would take more
> > than slight edits, so I'm hoping something's already out there. For
> > example, one should be able to go back to a function, tweak it, and
> > reload with a minimum of keyboard fuss.
>
> Well, if you consider the shell mode, there's an easy way to get what
> you want: just edit your commands, one by one, and type RET to try
> them. When you're happy with the result, type: history RET and
> copy-and-paste all the commands to a shell script buffer, add some
> minor edits, including a #!/bin/bash on the first line, and voilà.
This does not work very well with loops and functions and is more
cumbersome than necessary besides, avoiding which is the whole point
of learning Emacs.
> But really, I would rather start from the shell-script-mode.
<snip>
> Once you have implemented a pair of functions forward-shell-expression
> and backward-shell-expression, you can easily implement a function
> such as eval-last-shell-expression:
>
> (defun eval-last-shell-expression (point)
> (interactiev "P")
> (let ((start (progn (backward-shell-expression) (point)))
> (end (progn (forward-shell-expression) (point))))
> (comint-send-string (inferior-shell-proc)
> (buffer-substring start end))
> (comint-send-string (inferior-shell-proc) "\n")))
>
> There remains only to bind these commands to C-M-f, C-M-b and C-x C-e.
Yes, I think this and shell-script-mode should put me well on my way.
> But if you're as lazy as me, perhaps the best option would be to use
> scsh. You get a shell, but it's really a scheme, and there is already
> all you need to edit scheme scripts, and C-x C-e already works.
That does look really cool. I only hesitate because obviously regular
shells are installed everywhere. This is probably not as great an
advantage as it seems in my mind, though.
> --
> __Pascal Bourguignon__ http://www.informatimago.com/
>
Michael
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash Script Editing Mode?
[not found] ` <mailman.16033.1218143342.18990.help-gnu-emacs@gnu.org>
@ 2008-08-07 22:01 ` formido
0 siblings, 0 replies; 9+ messages in thread
From: formido @ 2008-08-07 22:01 UTC (permalink / raw
To: help-gnu-emacs
> ,----[ C-h f shell-command-on-region RET ]
> | shell-command-on-region is an interactive compiled Lisp function in
> | `simple.el'.
> A + Thierry Volpiatto
> Location: Saint-Cyr-Sur-Mer - France
I think this uses the region as input rather than the source of
commands to execute.
Michael
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash Script Editing Mode?
[not found] ` <mailman.16028.1218142452.18990.help-gnu-emacs@gnu.org>
@ 2008-08-07 22:03 ` formido
0 siblings, 0 replies; 9+ messages in thread
From: formido @ 2008-08-07 22:03 UTC (permalink / raw
To: help-gnu-emacs
> You can search for available commands from the help menu. Major modes
> are commands so you can use the menu entry
>
> Help
> Search Documentation
> Find Commands by Name
>
> I guessed that such a major mode would match
>
> ^sh.*-mode$
>
> and found some that might help you (I am not sure).
That's pretty helpful, although I'm not sure I would have thought to
lead with 'sh' sadly. I was doing searches on 'bash' and 'shell'.
Since sh-mode appears to be an alias for shell-script-mode, I guess I
would have found that, though.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bash Script Editing Mode?
2008-08-07 20:49 ` Mike Treseler
@ 2008-08-07 22:10 ` formido
0 siblings, 0 replies; 9+ messages in thread
From: formido @ 2008-08-07 22:10 UTC (permalink / raw
To: help-gnu-emacs
> This looks interesting:http://bashdb.sourceforge.net/bashdb.html#SEC2
True, although, unless I'm missing something, I don't think that works
for what I want right now out of the box. Hooking that up to my dream
bash repl will have to be a future project, although I would typically
use python instead of bash if it were going to be trouble enough to
warrant that much debugging power.
Michael
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-08-07 22:10 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-07 20:21 Bash Script Editing Mode? formido
2008-08-07 20:49 ` Mike Treseler
2008-08-07 22:10 ` formido
2008-08-07 20:53 ` Lennart Borgman (gmail)
2008-08-07 21:06 ` Thierry Volpiatto
2008-08-07 21:20 ` Pascal J. Bourguignon
2008-08-07 21:59 ` formido
[not found] ` <mailman.16033.1218143342.18990.help-gnu-emacs@gnu.org>
2008-08-07 22:01 ` formido
[not found] ` <mailman.16028.1218142452.18990.help-gnu-emacs@gnu.org>
2008-08-07 22:03 ` formido
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.