Skip to content

Commit

Permalink
v1.4 quickly install and uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
yinan-c committed Nov 3, 2023
1 parent 978b41c commit 7d170c3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions brewinfo.py
Expand Up @@ -80,17 +80,33 @@ def get_brew_leaves():
},
"arg": line,
"autocomplete": line,
"quicklookurl": f'https://formulae.brew.sh/formula/{line}'
"quicklookurl": f'https://formulae.brew.sh/formula/{line}',
"mods": {
"cmd": {
"valid": True,
"subtitle": 'brew uninstall ' + line,
"arg": 'brew uninstall ' + line,
},
},
})
return result

def get_brew_list(brewtype='all'):
if brewtype == 'cask':
output = subprocess.run(['brew', 'list', '--versions', '--cask'], capture_output=True, text=True)
uninstall_command = 'brew uninstall --cask '
force_uninstall_command = 'brew uninstall --cask --force --zap '
icon_path = {"path": "icons/cask_check.png"}
elif brewtype == 'formula':
output = subprocess.run(['brew', 'list', '--versions', '--formula'], capture_output=True, text=True)
uninstall_command = 'brew uninstall '
force_uninstall_command = 'brew uninstall '
icon_path = {"path": "icons/formula_check.png"}
else:
output = subprocess.run(['brew', 'list', '--versions'], capture_output=True, text=True)
uninstall_command = 'brew uninstall '
force_uninstall_command = 'brew uninstall --force '
icon_path = {"path": "icons/check.png"}
lines = output.stdout.split('\n')
result = {"items": []}
for line in lines:
Expand All @@ -100,11 +116,21 @@ def get_brew_list(brewtype='all'):

result["items"].append({
"title": f'{name} - {version}',
"icon": {
"path": "icons/check.png"
},
"icon": icon_path,
"arg": name,
"autocomplete": name
"autocomplete": name,
"mods": {
"alt": {
"valid": True,
"subtitle": uninstall_command + name,
"arg": uninstall_command + name,
},
"cmd": {
"valid": True,
"subtitle": force_uninstall_command + name,
"arg": force_uninstall_command + name,
},
},
})
return result

Expand All @@ -117,13 +143,15 @@ def get_all_formula_names(brewtype):
if brewtype == 'cask':
name = item['name'][0]
token = item['token']
install_command = 'brew install --cask ' + token
try:
subtitle = name + ' ℹ️ '+ item['desc']
except:
subtitle = name
elif brewtype == 'formula':
token = item['name']
subtitle = item['desc']
install_command = 'brew install ' + token
formula = {
"valid": True,
"title": token,
Expand All @@ -132,7 +160,14 @@ def get_all_formula_names(brewtype):
"icon": icon_path,
"autocomplete": token,
"quicklookurl": f'https://formulae.brew.sh/{brewtype}/{token}',
"match": brewtype + ' ' + token
"match": brewtype + ' ' + token,
"mods": {
"cmd": {
"valid": True,
"subtitle": install_command,
"arg": install_command,
},
},
}
items.append(formula)
return items
Expand Down Expand Up @@ -188,7 +223,9 @@ def get_info(brewtype,formula_name):
output_data['items'].extend(get_all_formula_names(brewtype='cask'))
output_data['items'].extend(get_all_formula_names(brewtype='formula'))
elif sys.argv[1] == 'list':
output_data = get_brew_list()
# output_data = get_brew_list()
output_data['items'].extend(get_brew_list(brewtype='cask')['items'])
output_data['items'].extend(get_brew_list(brewtype='formula')['items'])
elif sys.argv[1] == 'leaves':
output_data = get_brew_leaves()
elif sys.argv[1] == 'get_info':
Expand Down
Binary file added cask_check.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added formula_check.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7d170c3

Please sign in to comment.