daneah / iterm-components

:computer: Custom status bar components for use with iTerm2

Home Page:https://www.iterm2.com/3.3/documentation-status-bar.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create environment for AutoLaunch components

daneah opened this issue Β· comments

It would open a lot of doors to enable long-running components to use third-party packages.

Long-running components need to be placed in the AutoLaunch folder. The docs mention that scripts can have their own full environment via pyenv if done correctly, but I wasn't able to create a directory structure that seemed to work.

Even if you put a script in ~/Library/Application Support/iTerm2/Scripts/AutoLaunch/ you still have to manually enable it by checking scripts > AutoLaunch > script.py in iTerm. After that, it should automatically launch when you restart iTerm.

@harrygallagher4 Yep, that works like a charm. This issue is about being able to have an environment around a script that enables you to use packages installed from e.g. PyPI.

Whoops, didn't read the issue thoroughly enough πŸ˜…

@daneah according to the tutorial you can do that with the Full Environment option.

This creates a virtual environment where you can use other packages.

I've tried that yesterday. The structure looks like this.

> pwd
/Users/danieltrautmann/Library/Application Support/iTerm2/Scripts/AutoLaunch

> tree -L 3
.
└── status_bar
    β”œβ”€β”€ iterm2env
    β”‚   β”œβ”€β”€ iterm2env-metadata.json
    β”‚   β”œβ”€β”€ pyenv
    β”‚   β”œβ”€β”€ shims
    β”‚   └── versions
    β”œβ”€β”€ setup.cfg
    └── status_bar
        └── status_bar.py

Since I'm working on something similar you did, I'd be happy to help. However I'm not a Python expert.

@DanielTrautmann Thanks for the additional info. I keep meaning to look (and respond to you!) but haven't been able to find the time just yet. I don't have a particular component in mind to test this out with yet, either, but maybe soon πŸ˜„ if you do in the meantime and want to propose any additions, I'd welcome them πŸ’–

I'll try to create a component that shows due tasks of a Todoist account.

It seems that iTerm2 only installs the virtualenv when you create a new script via the GUI. So it is hard to provide scripts.

iTerm2 creates a file called setup.cfg and I thought this is used to setup the environment, but when you copy the directory containing the scripts to the iTerm2 Scripts directory. It doesn't create the environment automatically and I wasn't able to find a way to do it manually.

This is what the setup.cfg looks like:

# WARNING: This file was generated automatically by iTerm2. Do not edit it manually.
[metadata]
name=foo
version=1.0

[options]
scripts=foo/foo.py
install_requires=todoist-python; iterm2
python_requires = =3.8

[iterm2]
environment = >=62

Not sure if it is possible to use an environment which is not managed by iTerm2.

@DanielTrautmann Thanks so much for taking the time to investigate. That's pretty interesting. This might be enough for me to explore further, soon. setup.cfg is a common way to provide installation details, and install_requires is what's probably important here. The syntax seems fine, so might just be a matter of triggering iTerm2 to act on it.

Yes, the trigger is the part I couldn't find. Another option that came to my mind is to provide iterm-components as a pip package and let the user create a new script with iterm-components as dependency.

But then we would also need some kind of script to initialize iterm-components. In the end this is not an ideal solution.