Re: Proposed Prompt Escapes

2015-11-18 Thread isabella parakiss
On 11/19/15, Ángel González  wrote:
> Dennis Williamson wrote:
>> Do you mean something like:
>>
>> PS1='$SECONDS '
>
> Not exactly. $SECONDS is the number of seconds since the shell was
> started. I am interested in the seconds elapsed by the last command.
>
> It is a hacky solution, but it could be done with:
>> PS1=''; PROMPT_COMMAND='printf "%s " $SECONDS; SECONDS=0'
>
>

You need to reset it right before the command is executed, PROMPT_COMMAND
is evaluated when the prompt is drawn, before you type your command.
A debug trap is better suited, but you have to make sure that it's only
executed once in a complex line.

Something along these lines should work:

PROMPT_COMMAND=debug_trap=0
trap '((!debug_trap++))&&SECONDS=0' debug
PS1='$SECONDS \$ '


---
xoxo iza



Re: Proposed Prompt Escapes

2015-11-18 Thread Ángel González
Dennis Williamson wrote:
> Do you mean something like:
> 
> PS1='$SECONDS '

Not exactly. $SECONDS is the number of seconds since the shell was
started. I am interested in the seconds elapsed by the last command.

It is a hacky solution, but it could be done with:
> PS1=''; PROMPT_COMMAND='printf "%s " $SECONDS; SECONDS=0'



> (along with shopt -o promptvars)

For anyone trying to follow this, the above line should have been 
shopt -s promptvars (promptvars option is set by default)

Best regards



Re: Proposed Prompt Escapes

2015-11-17 Thread Dennis Williamson
On Tue, Nov 17, 2015 at 4:16 PM, Ángel González  wrote:

> While we are talking about new prompt escapes, I would love to be able
> to put in the prompt escapes elapsed time values from the previous
> command, so prefixing with time(1) could be redundant (if the intended
> resource was provided as an escape).
>
> Regards
>
>
Do you mean something like:

PS1='$SECONDS '

(along with shopt -o promptvars)

-- 
Visit serverfault.com to get your system administration questions answered.


Re: Proposed Prompt Escapes

2015-11-17 Thread Ángel González
While we are talking about new prompt escapes, I would love to be able
to put in the prompt escapes elapsed time values from the previous
command, so prefixing with time(1) could be redundant (if the intended resource 
was provided as an escape).

Regards



Re: Proposed Prompt Escapes

2015-11-10 Thread Dennis Williamson
On Tue, Nov 10, 2015 at 12:14 PM, Andreas Schwab 
wrote:

> Dennis Williamson  writes:
>
> > But wait, you don't need the intermediate step! It already works!!!
> >
> > prompt=$'\u, something about dominoes \U1F061  \@ '
>
> You should quote the backslashes.
>
> prompt=$'\\u, something about dominoes \U1F061  \\@ '
>
> Andreas.
>
> --
> Andreas Schwab, sch...@linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."
>


Thanks. That's better since it defers their evaluation which is important
when there is a conflict between the ANSI-C escapes and the prompt escapes
(e.g. \u (user) followed immediately by hex chars, \t, \v).


-- 
Visit serverfault.com to get your system administration questions answered.


Re: Proposed Prompt Escapes

2015-11-10 Thread Andreas Schwab
Dennis Williamson  writes:

> But wait, you don't need the intermediate step! It already works!!!
>
> prompt=$'\u, something about dominoes \U1F061  \@ '

You should quote the backslashes.

prompt=$'\\u, something about dominoes \U1F061  \\@ '

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: Proposed Prompt Escapes

2015-11-10 Thread Dennis Williamson
On Mon, Nov 9, 2015 at 5:09 PM, Dennis Williamson <
dennistwilliam...@gmail.com> wrote:

>
>
> On Thu, Nov 5, 2015 at 6:26 PM, Dennis Williamson <
> dennistwilliam...@gmail.com> wrote:
>
>> It might be handy to have some of the escapes that work in $'string'
>> quoting to also work in prompts especially now with the ${parameter@P}
>> transformation.
>>
>> Specifically the hex, unicode and control ones: \xHH, \u, \U
>> and \cx.
>>
>> I presume that the dollar-single-quote escapes should not be touched
>> since they are "specified by the ANSI C standard". Also, they needn't be
>> since we have the @P transformation.
>>
>> --
>> Visit serverfault.com to get your system administration questions
>> answered.
>>
>
>
> I obviously overlooked the collision between \u - username and \u -
> unicode. It could be dealt with by interpreting the escape as username if
> the following character is non-hex, but that would stand a good chance of
> breaking existing prompts. Since \U functionally is a complete superset of
> \u - unicode, perhaps the latter wouldn't need to be duplicated for
> prompting.
>
>
> --
> Visit serverfault.com to get your system administration questions
> answered.
>


Of course, the obvious way to do this is to assign a variable using
$'\u' or similar.

dbl_6_dom=$'\U1F061'
prompt='\u, something about dominoes $dbl_6_dom \@ '
echo "${prompt@P}"

But wait, you don't need the intermediate step! It already works!!!

prompt=$'\u, something about dominoes \U1F061  \@ '
echo "${prompt@P}"


-- 
Visit serverfault.com to get your system administration questions answered.


Re: Proposed Prompt Escapes

2015-11-09 Thread Dennis Williamson
On Thu, Nov 5, 2015 at 6:26 PM, Dennis Williamson <
dennistwilliam...@gmail.com> wrote:

> It might be handy to have some of the escapes that work in $'string'
> quoting to also work in prompts especially now with the ${parameter@P}
> transformation.
>
> Specifically the hex, unicode and control ones: \xHH, \u, \U
> and \cx.
>
> I presume that the dollar-single-quote escapes should not be touched since
> they are "specified by the ANSI C standard". Also, they needn't be since we
> have the @P transformation.
>
> --
> Visit serverfault.com to get your system administration questions
> answered.
>


I obviously overlooked the collision between \u - username and \u -
unicode. It could be dealt with by interpreting the escape as username if
the following character is non-hex, but that would stand a good chance of
breaking existing prompts. Since \U functionally is a complete superset of
\u - unicode, perhaps the latter wouldn't need to be duplicated for
prompting.


-- 
Visit serverfault.com to get your system administration questions answered.


Proposed Prompt Escapes

2015-11-05 Thread Dennis Williamson
It might be handy to have some of the escapes that work in $'string'
quoting to also work in prompts especially now with the ${parameter@P}
transformation.

Specifically the hex, unicode and control ones: \xHH, \u, \U
and \cx.

I presume that the dollar-single-quote escapes should not be touched since
they are "specified by the ANSI C standard". Also, they needn't be since we
have the @P transformation.

-- 
Visit serverfault.com to get your system administration questions answered.