zsh-users
 help / color / mirror / code / Atom feed
* ZSH feature request if not present
@ 2015-10-14 14:50 jagmeet bali
  2015-10-14 15:14 ` ZyX
  2015-10-15  6:10 ` Best Way to Test an Environment Variable czech
  0 siblings, 2 replies; 7+ messages in thread
From: jagmeet bali @ 2015-10-14 14:50 UTC (permalink / raw)
  To: zsh-users

Hey is there a way where I can search all the commands I ran in a
particular directory.
Similar to forward or reverse search but all the commands which were run in that
pwd should be searched.
I have just started using zsh. So pardon my ignorance. Thanks in advance.

Regards
Bali


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: ZSH feature request if not present
  2015-10-14 14:50 ZSH feature request if not present jagmeet bali
@ 2015-10-14 15:14 ` ZyX
  2015-10-14 15:55   ` Peter Stephenson
  2015-10-15  6:10 ` Best Way to Test an Environment Variable czech
  1 sibling, 1 reply; 7+ messages in thread
From: ZyX @ 2015-10-14 15:14 UTC (permalink / raw)
  To: jagmeet bali, zsh-users

14.10.2015, 17:52, "jagmeet bali" <jagmeet.bali@gmail.com>:
> Hey is there a way where I can search all the commands I ran in a
> particular directory.
> Similar to forward or reverse search but all the commands which were run in that
> pwd should be searched.
> I have just started using zsh. So pardon my ignorance. Thanks in advance.
>
> Regards
> Bali

No, current directory is not saved. There was [some SO question][1] where it was discussed how to save pwd in history alongside with the command (using zshaddhistory hook). You need to take it and create a ZLE widget that searches among entries with needed pwd. No built-in functionality I know is present that may satisfy your request.

[1]: http://stackoverflow.com/questions/2824051/saving-current-directory-to-zsh-history


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: ZSH feature request if not present
  2015-10-14 15:14 ` ZyX
@ 2015-10-14 15:55   ` Peter Stephenson
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 2015-10-14 15:55 UTC (permalink / raw)
  To: zsh-users

On Wed, 14 Oct 2015 18:14:01 +0300
ZyX <kp-pav@yandex.ru> wrote:
> No, current directory is not saved. There was [some SO question][1]
> where it was discussed how to save pwd in history alongside with the
> command (using zshaddhistory hook). You need to take it and create a
> ZLE widget that searches among entries with needed pwd. No built-in
> functionality I know is present that may satisfy your request.

Here's my function zshaddhistory-local that does what I want, which is
save the history within the directory, but only if there's already a
file there already --- so this is only useful for a small number of
locations you're particularly interested in.  I've never been confident
it's of general enough use to put it in the distribution.  There's a
companion file history-beginning-local for binding to \ep to search the
local history in preference to the global one, which I haven't posted
--- this is where it really gets a bit of a mess since that essentially
re-implements the core of history-beginning-search-backward.

You need

autoload -Uz add-zsh-hook zshaddhistory-local
add-zsh-hook -Uz zshaddhistory zshaddhistory-local

pws


# This function is an adjunct to the history-beginning-local
# zle widget.  It saves any history entries that would be
# found by that widget in the local history file, provided that
# already exists.  It also saves the history globally unless
# the local-history-only style is set in the context.
#
# The context is :zhist: followed by the function name, a colon, the
# current directory from $PWD, and another colon.

emulate -L zsh
setopt extendedglob warncreateglobal

zmodload -i zsh/parameter

local name=${funcstack[1]} lhp f
local -a lhf lhc
integer lho

zstyle -a ":zhist:${name}:${PWD}:" local-history-file lhf || return 1
zstyle -a ":zhist:${name}:${PWD}:" local-history-commands lhc || return 1
zstyle -s ":zhist:${name}:${PWD}:" local-history-pattern lhp
zstyle -t ":zhist:${name}:${PWD}:" local-history-only && lho=1

for f in $lhf; do
  if [[ -w $f ]]; then
    local -a words

    words=(${(z)1})
    if [[ ${(Q)words[1]} = (${(j.|.)~lhc}) || \
      ( -n $lhp && $1 = ${~lhp} ) ]]; then
      # Save on the global history unless we're told not to.
      # If we define multiple zshaddhistory hooks we want a
      # a way of signalling that we've done this.  One way
      # of doing this would be to set a global parameter to $HISTCMD,
      # although that doesn't change if we've ignored the previous line.
      # Another way would be to have a zshaddhistoryhook that reset
      # a global parameter (since this is called first) and rely
      # on all the other hooks being in zshaddhistory_functions,
      # as they should be for neatness.
      (( lho )) || print -Sr -- ${1%%$'\n'}
      fc -p -- $f
      break
    fi
  fi
done


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Best Way to Test an Environment Variable
  2015-10-14 14:50 ZSH feature request if not present jagmeet bali
  2015-10-14 15:14 ` ZyX
@ 2015-10-15  6:10 ` czech
  2015-10-15  6:32   ` czech
  1 sibling, 1 reply; 7+ messages in thread
From: czech @ 2015-10-15  6:10 UTC (permalink / raw)
  To: zsh-users

Hi -

I've been using:

if [ -z $ENV_VAR ]; then

    <do stuff>
fi

To test environment variables. It seems to work.

But I'm curious - is there a better way in zsh to test an environment
variable?

Thanks,



Corwin


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Best Way to Test an Environment Variable
  2015-10-15  6:10 ` Best Way to Test an Environment Variable czech
@ 2015-10-15  6:32   ` czech
  2015-10-15  9:46     ` Roman Neuhauser
  0 siblings, 1 reply; 7+ messages in thread
From: czech @ 2015-10-15  6:32 UTC (permalink / raw)
  To: zsh-users

I probably should have clarified - the objective of the test is to see if
the environment variable is set or not. -z $ENV_VAR seems to return 1 if
the environment variable is not set or is set to null (zero bytes).

Thanks,



Corwin

> Hi -
>
> I've been using:
>
> if [ -z $ENV_VAR ]; then
>
>     <do stuff>
> fi
>
> To test environment variables. It seems to work.
>
> But I'm curious - is there a better way in zsh to test an environment
> variable?
>
> Thanks,
>
>
>
> Corwin
>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Best Way to Test an Environment Variable
  2015-10-15  6:32   ` czech
@ 2015-10-15  9:46     ` Roman Neuhauser
  2015-10-15 17:34       ` Corwin
  0 siblings, 1 reply; 7+ messages in thread
From: Roman Neuhauser @ 2015-10-15  9:46 UTC (permalink / raw)
  To: czech; +Cc: zsh-users

# czech@sonic.net / 2015-10-14 23:32:40 -0700:
> I probably should have clarified - the objective of the test is to see if
> the environment variable is set or not. -z $ENV_VAR seems to return 1 if
> the environment variable is not set or is set to null (zero bytes).

zshexpn(1):

  ${+name}
      If name is the name of a set parameter `1' is substituted,
      otherwise `0' is substituted.

ps your first email is a reply to an email with a completely unrelated
topic.  don't do that.

  891     Oct 14 jagmeet bali    (  49) ZSH feature request if not present
  892     Oct 14 ZyX             (  53) |->
  893     Oct 14 Peter Stephenso ( 120) | `->
  894     Oct 14 czech@sonic.net (  60) `->Best Way to Test an Environment Variable
  895     Oct 14 czech@sonic.net (  73)   `->

-- 
roman


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Best Way to Test an Environment Variable
  2015-10-15  9:46     ` Roman Neuhauser
@ 2015-10-15 17:34       ` Corwin
  0 siblings, 0 replies; 7+ messages in thread
From: Corwin @ 2015-10-15 17:34 UTC (permalink / raw)
  To: zsh-users

Hi Roman -

Thanks for the pointer to zshexpn. I will refrain from replying to a 
different topic with a new topic.

Regards,



Corwin

On 2015-10-15 02:46, Roman Neuhauser wrote:
> # czech@sonic.net / 2015-10-14 23:32:40 -0700:
>> I probably should have clarified - the objective of the test is to see 
>> if
>> the environment variable is set or not. -z $ENV_VAR seems to return 1 
>> if
>> the environment variable is not set or is set to null (zero bytes).
> 
> zshexpn(1):
> 
>   ${+name}
>       If name is the name of a set parameter `1' is substituted,
>       otherwise `0' is substituted.
> 
> ps your first email is a reply to an email with a completely unrelated
> topic.  don't do that.
> 
>   891     Oct 14 jagmeet bali    (  49) ZSH feature request if not 
> present
>   892     Oct 14 ZyX             (  53) |->
>   893     Oct 14 Peter Stephenso ( 120) | `->
>   894     Oct 14 czech@sonic.net (  60) `->Best Way to Test an
> Environment Variable
>   895     Oct 14 czech@sonic.net (  73)   `->


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-10-15 17:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-14 14:50 ZSH feature request if not present jagmeet bali
2015-10-14 15:14 ` ZyX
2015-10-14 15:55   ` Peter Stephenson
2015-10-15  6:10 ` Best Way to Test an Environment Variable czech
2015-10-15  6:32   ` czech
2015-10-15  9:46     ` Roman Neuhauser
2015-10-15 17:34       ` Corwin

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).