daneah / iterm-components Goto Github PK
View Code? Open in Web Editor NEW:computer: Custom status bar components for use with iTerm2
Home Page: https://www.iterm2.com/3.3/documentation-status-bar.html
License: MIT License
:computer: Custom status bar components for use with iTerm2
Home Page: https://www.iterm2.com/3.3/documentation-status-bar.html
License: MIT License
It would be cool for the GitHub stars component to open the configured repo in the browser on click via:
@iterm2.RPC
def click_handler(session_id):
repo = ...
proc = await asyncio.create_subprocess_shell(
f'open https://github.com/{repo}',
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
stdout, stderr = await proc.communicate()
Unfortunately, the repo
value is only available in the knobs
, which can't be passed to the onclick
coroutine. This is perhaps possible with some magic since the @StatusBarRPC
coroutine does receive the knobs, but it was out of my reach.
Great stuff you have going here, I just need to get it working :)
I want the kubernetes context in my status bar, but it is just blank. My guess is that the script is running in some weird context so it doesn't have access to kubectl.
Is there a way to verify my assumption? Do you know how to fix it?
As long as a status bar doesn't need to be interactive and only displays the output from a command it can be solved in a generic manner.
It should work basically as kubectl_context.py
but instead of having a fixed command it should be able to configure the command as well as defining a prefix to make it look prettier in the status bar.
I tried using your Hello World example to get something working (I would like to help build out the reading of a session environment variable if possible). Anyways, I used an interpolated string with this value: \(hello_world_coroutine(knobs: "{}"))
. When I open iterm it will display a random greeting, but it never changes. Am I doing something wrong? I realize that this isn't necessarily an issue with your code, but I would greatly appreciate the assistance and would like to help you with this project as I see value in it.
Looks like a symlink issue.
Installation: (note- I had copied generic_command earlier)
epedrosa@3Y:~/git$ git clone https://github.com/daneah/iterm-components.git
Cloning into 'iterm-components'...
remote: Enumerating objects: 144, done.
remote: Total 144 (delta 0), reused 0 (delta 0), pack-reused 144
Receiving objects: 100% (144/144), 283.85 KiB | 2.87 MiB/s, done.
Resolving deltas: 100% (72/72), done.
epedrosa@3Y:~/git$ cd iterm-components/
epedrosa@3Y:~/git/iterm-components$ ./install.sh
Linking scripts to AutoLaunch folder /Users/epedrosa/Library/Application Support/iTerm2/Scripts/AutoLaunch
Linking WIP_environment_variable.py...
Linking generic_command.py...
replace /Users/epedrosa/Library/Application Support/iTerm2/Scripts/AutoLaunch/generic_command.py? y
Linking github_stars.py...
Linking hello_world.py...
Linking kubectl_context.py...
Linking pyenv.py...
Linking rvm_gemset.py...
Selected scripts | autolaunch | hello_world.py...
Log:
3/21, 4:50:43.745 PM: /bin/bash -c /Users/epedrosa/Applications/iTerm.app/Contents/Resources/it2_api_wrapper.sh /Users/epedrosa/Library/ApplicationSupport/iTerm2/iterm2env/versions/3.8.0/bin/python3 /Users/epedrosa/Library/ApplicationSupport/iTerm2/Scripts/Autolaunch/hello_world.py
3/21, 4:50:43.764 PM: + unset PYTHONPATH
3/21, 4:50:43.764 PM: + export PYTHONUNBUFFERED=1
3/21, 4:50:43.764 PM: + PYTHONUNBUFFERED=1
3/21, 4:50:43.764 PM: + /Users/epedrosa/Library/ApplicationSupport/iTerm2/iterm2env/versions/3.8.0/bin/python3 /Users/epedrosa/Library/ApplicationSupport/iTerm2/Scripts/Autolaunch/hello_world.py
3/21, 4:50:43.810 PM: /Users/epedrosa/Library/ApplicationSupport/iTerm2/iterm2env/versions/3.8.0/bin/python3: can't open file '/Users/epedrosa/Library/ApplicationSupport/iTerm2/Scripts/Autolaunch/hello_world.py': [Errno 62] Too many levels of symbolic links
3/21, 4:50:43.810 PM:
3/21, 4:50:43.810 PM: ** Script exited with status 2 **
Replaced link with copy of script
epedrosa@3Y:~/git/iterm-components$ rm ~/Library/ApplicationSupport/iTerm2/Scripts/Autolaunch/hello_world.py
epedrosa@3Y:~/git/iterm-components$ cp hello_world.py ~/Library/ApplicationSupport/iTerm2/Scripts/Autolaunch/
Runs successfully now.
3/21, 4:52:42.385 PM: /bin/bash -c /Users/epedrosa/Applications/iTerm.app/Contents/Resources/it2_api_wrapper.sh /Users/epedrosa/Library/ApplicationSupport/iTerm2/iterm2env/versions/3.8.0/bin/python3 /Users/epedrosa/Library/ApplicationSupport/iTerm2/Scripts/Autolaunch/hello_world.py
3/21, 4:52:42.411 PM: + unset PYTHONPATH
3/21, 4:52:42.411 PM: + export PYTHONUNBUFFERED=1
3/21, 4:52:42.411 PM: + PYTHONUNBUFFERED=1
3/21, 4:52:42.411 PM: + /Users/epedrosa/Library/ApplicationSupport/iTerm2/iterm2env/versions/3.8.0/bin/python3 /Users/epedrosa/Library/ApplicationSupport/iTerm2/Scripts/Autolaunch/hello_world.py
3/21, 4:52:42.845 PM: Connection accepted: Script launched by user action
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.
I can't figure out how to get components to run in the context of the current shell, which means things like pyenv
and rvm
don't work since they require loading. The WIP components work when run manually in a virtualenv, but not when placed in the AutoLaunch
folder.
When the component is added to the status bar and configured, a ladybug shows in the status bar. Clicking returns this error:
Status bar component “GitHub stars” (engineering.dane.iterm-components.github-stars) failed.
This function call had an error:
statusbar.engineering.dane.iterm_components.github_stars.github_stars_coroutine(knobs:__knobs)
The error was:
Reference to undefined variable “__knobs”. Change it to “__knobs?” to treat the undefined value as null.
I think something has changed with the way this variable is scoped, maybe?
It would be awesome if the kubectl context component, when clicked, would show a popover menu of the available contexts via:
kubectl config view -o jsonpath='{.contexts[*].name}' | tr " " "\n"
And switch to one of the displayed contexts when clicked via:
kubectl config use-context <context>
The popover is covered well in the docs (see onclick
in this example) but being able to click items inside the popover isn't AFAICT.
The built in git state
component does something like this, but the built-ins all appear to be written in Objective-C.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.