ytet5uy4 / fzf-widgets

ZLE widgets of fzf
MIT License
87 stars 18 forks source link

command not found: private #7

Closed popstas closed 7 years ago

popstas commented 7 years ago

Hello, I'm trying to include widgets with antigen. Widgets loads on macOS, but on Ubuntu outputs many errors begins with:

command not found: private
$ private
zsh: command not found: private
ytet5uy4 commented 7 years ago

Hello @popstas. The private is available in zsh since version 5.2, so I will add about this to README. Thank you for report.

popstas commented 7 years ago

@ytet5uy4, are you know fast solution (maybe polyfill), how to rewrite your plugin without private? I'm using my zsh config on several servers including Debian 6 with zsh 4.3.10. I want to fork your plugin and include to my ansible role

ytet5uy4 commented 7 years ago

Hmm. You should probably use local instead of private.

If add the following to init.zsh, might work.

is-at-least 5.2 || private() { local }
popstas commented 7 years ago

Unfortunately, it not work so easy, but it work! local have other scope.

For example:

is-at-least 5.2 || private() { local }

: "Create cache directory" && () {
  if [[ -n $XDG_CACHE_HOME ]]; then
    [[ ! -d $XDG_CACHE_HOME ]] && mkdir $XDG_CACHE_HOME
    private dir="$XDG_CACHE_HOME/fzf-widgets"
  else
    private dir="/tmp/fzf-widgets"
  fi

  # test variable
  echo "dir = $dir"
}

Outputs dir =

But:

is-at-least 5.2 || private() { local }

: "Create cache directory" && () {
  if [[ -n $XDG_CACHE_HOME ]]; then
    [[ ! -d $XDG_CACHE_HOME ]] && mkdir $XDG_CACHE_HOME
    dir="$XDG_CACHE_HOME/fzf-widgets"
  else
    dir="/tmp/fzf-widgets"
  fi

  # test variable
  echo "dir = $dir"
}

Outputs dir = /tmp/fzf-widgets.

What benefits give using of private? Maybe better to rewrite for local? Debian stable, Ubuntu 16.04, CentOS 7 - all have zsh < 5.2.

Anyway, I will try to do it, do you merge such PR?

ytet5uy4 commented 7 years ago

I'm sorry, I gave you wrong information. :bowing_man:

The advantages of private is scope limited than local. http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fparam_002fprivate-Module

I'm using only ArchLinux on laptop and server, so I didn't care zsh version. However I feel I should support zsh versions earlier than 5.2. If you rewrite private to local as follows and send such PR, I merge it.

Before:

: "Create cache directory" && () {
  if [[ -n $XDG_CACHE_HOME ]]; then
    [[ ! -d $XDG_CACHE_HOME ]] && mkdir $XDG_CACHE_HOME
    private dir="$XDG_CACHE_HOME/fzf-widgets"
  else
    private dir="/tmp/fzf-widgets"
  fi
}

After:

: "Create cache directory" && () {
  if [[ -n $XDG_CACHE_HOME ]]; then
    [[ ! -d $XDG_CACHE_HOME ]] && mkdir $XDG_CACHE_HOME
    local dir="$XDG_CACHE_HOME/fzf-widgets"
  else
    local dir="/tmp/fzf-widgets"
  fi
}

https://github.com/robbyrussell/oh-my-zsh/wiki/Coding-style-guide#use-local-variables

ytet5uy4 commented 7 years ago

NOTE:

: "Create cache directory" && () {
  if [[ -n $XDG_CACHE_HOME ]]; then
    [[ ! -d $XDG_CACHE_HOME ]] && mkdir $XDG_CACHE_HOME
    local dir="$XDG_CACHE_HOME/fzf-widgets"
  else
    local dir="/tmp/fzf-widgets"
  fi

  # test variable
  echo "dir = $dir"
}

Outputs dir = /tmp/fzf-widgets.

popstas commented 7 years ago

Fixed in #15