Skip to content

Commit e07a4bc

Browse files
committed
initial commit
Signed-off-by: Aviv Ben-David <[email protected]>
1 parent 8bc4926 commit e07a4bc

12 files changed

+354
-0
lines changed

.github/workflows/Publish Release.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Publish Release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main ]
7+
paths-ignore:
8+
- .github/workflows/*
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
env:
14+
python_ver: 3.8
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: get version
23+
id: version
24+
uses: notiz-dev/github-action-json-property@release
25+
with:
26+
path: 'plugin.json'
27+
prop_path: 'Version'
28+
- run: echo ${{steps.version.outputs.prop}}
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install -r ./requirements.txt -t ./lib
33+
zip -r Flow.Launcher.Plugin.HelloWorldPython.zip . -x '*.git*'
34+
- name: Publish
35+
if: success()
36+
uses: softprops/action-gh-release@v1
37+
with:
38+
files: 'Flow.Launcher.Plugin.HelloWorldPython.zip'
39+
tag_name: "v${{steps.version.outputs.prop}}"
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode
4+
5+
### Python ###
6+
# Byte-compiled / optimized / DLL files
7+
__pycache__/
8+
*.py[cod]
9+
*$py.class
10+
11+
# C extensions
12+
*.so
13+
14+
# Distribution / packaging
15+
.Python
16+
build/
17+
develop-eggs/
18+
dist/
19+
downloads/
20+
eggs/
21+
.eggs/
22+
lib/
23+
lib64/
24+
parts/
25+
sdist/
26+
var/
27+
wheels/
28+
share/python-wheels/
29+
*.egg-info/
30+
.installed.cfg
31+
*.egg
32+
MANIFEST
33+
34+
# PyInstaller
35+
# Usually these files are written by a python script from a template
36+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
37+
*.manifest
38+
*.spec
39+
40+
# Installer logs
41+
pip-log.txt
42+
pip-delete-this-directory.txt
43+
44+
# Unit test / coverage reports
45+
htmlcov/
46+
.tox/
47+
.nox/
48+
.coverage
49+
.coverage.*
50+
.cache
51+
nosetests.xml
52+
coverage.xml
53+
*.cover
54+
*.py,cover
55+
.hypothesis/
56+
.pytest_cache/
57+
cover/
58+
59+
# Translations
60+
*.mo
61+
*.pot
62+
63+
# Django stuff:
64+
*.log
65+
local_settings.py
66+
db.sqlite3
67+
db.sqlite3-journal
68+
69+
# Flask stuff:
70+
instance/
71+
.webassets-cache
72+
73+
# Scrapy stuff:
74+
.scrapy
75+
76+
# Sphinx documentation
77+
docs/_build/
78+
79+
# PyBuilder
80+
.pybuilder/
81+
target/
82+
83+
# Jupyter Notebook
84+
.ipynb_checkpoints
85+
86+
# IPython
87+
profile_default/
88+
ipython_config.py
89+
90+
# pyenv
91+
# For a library or package, you might want to ignore these files since the code is
92+
# intended to run in multiple environments; otherwise, check them in:
93+
# .python-version
94+
95+
# pipenv
96+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
97+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
98+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
99+
# install all needed dependencies.
100+
#Pipfile.lock
101+
102+
# poetry
103+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
104+
# This is especially recommended for binary packages to ensure reproducibility, and is more
105+
# commonly ignored for libraries.
106+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
107+
#poetry.lock
108+
109+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
110+
__pypackages__/
111+
112+
# Celery stuff
113+
celerybeat-schedule
114+
celerybeat.pid
115+
116+
# SageMath parsed files
117+
*.sage.py
118+
119+
# Environments
120+
.env
121+
.venv
122+
env/
123+
venv/
124+
ENV/
125+
env.bak/
126+
venv.bak/
127+
128+
# Spyder project settings
129+
.spyderproject
130+
.spyproject
131+
132+
# Rope project settings
133+
.ropeproject
134+
135+
# mkdocs documentation
136+
/site
137+
138+
# mypy
139+
.mypy_cache/
140+
.dmypy.json
141+
dmypy.json
142+
143+
# Pyre type checker
144+
.pyre/
145+
146+
# pytype static type analyzer
147+
.pytype/
148+
149+
# Cython debug symbols
150+
cython_debug/
151+
152+
# PyCharm
153+
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
154+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
155+
# and can be added to the global gitignore or merged into this file. For a more nuclear
156+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
157+
#.idea/
158+
159+
### VisualStudioCode ###
160+
.vscode/*
161+
!.vscode/settings.json
162+
!.vscode/tasks.json
163+
!.vscode/launch.json
164+
!.vscode/extensions.json
165+
!.vscode/*.code-snippets
166+
167+
# Local History for Visual Studio Code
168+
.history/
169+
170+
# Built Visual Studio Code Extensions
171+
*.vsix
172+
173+
### VisualStudioCode Patch ###
174+
# Ignore all local history of files
175+
.history
176+
.ionide
177+
178+
# Support for Project snippet scope
179+
180+
# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode
181+
182+
lib

.vscode/settings.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"python.analysis.extraPaths": [
3+
"plugin",
4+
"lib"
5+
]
6+
}

Images/app.png

1.65 KB
Loading

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Windowss temirnal profiles launcher
2+
3+
https://github.com/microsoft/PowerToys/tree/main/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsTerminal

main.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import sys,os
4+
parent_folder_path = os.path.abspath(os.path.dirname(__file__))
5+
sys.path.append(parent_folder_path)
6+
sys.path.append(os.path.join(parent_folder_path, 'lib'))
7+
sys.path.append(os.path.join(parent_folder_path, 'plugin'))
8+
9+
from terminal_profiles import TerminalProfiles
10+
11+
if __name__ == "__main__":
12+
TerminalProfiles()

plugin.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"ID": "a56ae6ac-7b3b-47b9-857f-05ff25d29510",
3+
"ActionKeyword": "wt",
4+
"Name": "Windows Terminal profiles",
5+
"Description": "Windows Terminal profiles launcher",
6+
"Author": "Aviv B.D.",
7+
"Version": "0.0.1",
8+
"Language": "python",
9+
"Website": "https://github.com/paradox00/Flow.Launcher.Plugin.WindowsTerminal",
10+
"IcoPath": "Images\\app.png",
11+
"ExecuteFileName": "main.py"
12+
}

plugin/helpers.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import json
2+
from pathlib import Path
3+
4+
def json_load_comments(path: Path):
5+
lines = list()
6+
with open(path, "r") as f:
7+
for line in f:
8+
if line.strip().startswith("//"):
9+
continue
10+
11+
lines.append(line)
12+
13+
content = "".join(lines)
14+
return json.loads(content)

plugin/main.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from flowlauncher import FlowLauncher
2+
import flowlauncherAPI
3+
from flox import Flox
4+
5+
from terminal_profiles import TerminalProfiles, Terminal, TerminalProfile
6+
7+
class TerminalPlugin(Flox):
8+
def __init__(self) -> None:
9+
super().__init__()
10+
self.tp = TerminalProfiles()
11+
self.profiles = list(self.tp.find_profiles())
12+
13+
def query(self, query):
14+
for profile in self.profiles:
15+
if query in profile.name:
16+
17+
18+
def context_menu(self, data):
19+
pass
20+
21+
def reload(self):
22+
self.profiles = list(self.tp.find_profiles())

plugin/terminal_profile_test.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import terminal_profiles
2+
3+
def test():
4+
profiles = terminal_profiles.TerminalProfiles()
5+
print(list(profiles.find_installation()))
6+
7+
print(list(profiles.find_profiles()))
8+
9+
if __name__ == "__main__":
10+
test()

plugin/terminal_profiles.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from pathlib import Path
2+
from dataclasses import dataclass
3+
from typing import Iterable, Dict
4+
import os
5+
from helpers import json_load_comments
6+
7+
@dataclass
8+
class Terminal:
9+
package: str
10+
settings: Path
11+
12+
@dataclass
13+
class TerminalProfile:
14+
name: str
15+
guid: str
16+
hidden: bool
17+
terminal: Terminal
18+
19+
class TerminalProfiles:
20+
PACKAGES = [
21+
"Microsoft.WindowsTerminal",
22+
"Microsoft.WindowsTerminalPreview",
23+
]
24+
def __init__(self) -> None:
25+
pass
26+
27+
def find_installation(self) -> Iterable[Terminal]:
28+
local_app_data = os.getenv("LOCALAPPDATA")
29+
packages_path = Path(local_app_data, "packages")
30+
for directory in packages_path.iterdir():
31+
for package in self.PACKAGES:
32+
if directory.name.startswith(f"{package}_"):
33+
yield Terminal(package, directory / "LocalState" / "settings.json")
34+
35+
def find_profiles(self):
36+
for terminal in self.find_installation():
37+
if not terminal.settings.exists():
38+
continue
39+
40+
settings = json_load_comments(terminal.settings)
41+
for profile in settings["profiles"]["list"]:
42+
yield self.parse_profile(profile, terminal)
43+
44+
def parse_profile(self, profile: Dict, terminal: Terminal) -> TerminalProfile:
45+
return TerminalProfile(
46+
name = profile.get("name", ""),
47+
guid = profile.get("guid", ""),
48+
hidden = profile.get("hidden", "false") != "false",
49+
terminal = terminal
50+
)

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#flowlauncher
2+
git+https://github.com/garulf/flox.git

0 commit comments

Comments
 (0)