Code Monkey home page Code Monkey logo

zsh-hoco's Introduction

Great curassow, image designed by rawpixel.com / Freepik

HOCO - zsh hosts completion

Small function to improve and extend original zsh _hosts completion function.

Objectives

The original zsh hosts completion is not extendable. And when you replace it with zstyle -e ':completion:*:hosts' hosts 'reply=(...)', all original completions should be represented too.

On the other hand, _hosts caches all hosts for autocompletion only once, and then uses it. And it's not so obvious how to reset it.

Solution

The hoco.zsh solves both _hosts flaws:

  • It updates the cache once per $HOCO_CACHE_AGE period, the default is 10 minutes
  • It allows to update list of hosts dynamically. Each binary or function in $HOCO_FUNCTIONS array is executed asynchronously. The list of hosts for completion is updated on readiness.

Usage

The only thing you need to do is:

source hoco.zsh
some-function() {
  echo host1 host2 # it does not matter if hosts are separated by spaces
  echo host3	host4 # or by new lines (LF), or by tabs
}
HOCO_FUNCTIONS=(some-function)

ssh <tab>

zsh-hoco's People

Contributors

felixoid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

varenc

zsh-hoco's Issues

Consider option to control cache on ivalidation

Currently, the cache is just dropped on each update.

It's possible to make it configurable to stay available forever in case of problems.

Upd: it looks to me that I found the best way to implement it is using the builtins, a good example is in _perl_modules sources and following _store_cache, _retrieve_cache, and _cache_invalid functions

Implement async with zsh internals

After doing exec {fd}< <( ... ), you can use $sysparams[procsubstpid] to get the async process ID and save it for later, so you can kill it, if necessary.

You can use zsystem flock to lock the file you're going to write to. You can add a timeout to this command, so that when the lock doesn't succeed (because the file is already locked), it will time out and return non-zero.

source: https://www.reddit.com/r/zsh/comments/onlqmh/extension_of_hosts_completion_function/h60vkx4

tl;dr: it will allow to unvendor zsh-async and think about putting the function to zsh upstream

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.