Fix dotfiles structure

This commit is contained in:
2026-03-15 10:32:59 +05:30
parent ca014e9949
commit a2c3404cb2
2557 changed files with 148415 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
# Translate Widget
This widget allows quickly translate words or phrases without opening a browser - just using Awesome. To provide direction of the translation add the 2 letters code of the source and target languages at the end of the phrase, for example _hello enfr_ will translate _hello_ from English to French. This widget is based on [Watson Language Translator](https://www.ibm.com/watson/services/language-translator/) from IBM.
![demo](./demo.gif)
## Controls
- <kbd>Mod4</kbd> + <kbd>c</kbd> - opens a translate prompt;
- left click on the popup widget - copies the translation to the clipboard and closes widget;
- right click on the popup widget - copies text to translate to the clipboard and closes widget.
## Installation
1. Clone repo under **~/.config/awesome/**
1. Create an IBM Cloud API key at [cloud.ibm.com/iam/apikeys](https://cloud.ibm.com/iam/apikeys)
1. Copy a service URL by going to [resource list](https://cloud.ibm.com/resources), then under "Services" select "Language Translator" option, and then copy URL from the "Credentials" section
1. Require widget in **rc.lua**:
```lua
local translate = require("awesome-wm-widgets.translate-widget.translate")
```
1. Add a shortcut to run translate prompt:
```lua
awful.key({ modkey }, "c", function()
translate.launch{api_key = '<api-key>', url = 'url'}
end, { description = "run translate prompt", group = "launcher" })
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@@ -0,0 +1,12 @@
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" version="1">
<path style="opacity:0.5" d="M 16,32 32,44 V 20 L 16,4 Z"/>
<path style="fill:#e4e4e4" d="M 6,16 C 4.892,16 4,16.892 4,18 V 42 C 4,43.108 4.892,44 6,44 H 32 V 16 Z"/>
<path style="opacity:0.2" d="M 15.403,22.554 C 16.003,22.97 16.557,23.478 17.065,24.078 L 16.165,25.186 C 15.611,24.493 15.034,23.916 14.433,23.454 L 15.403,22.554 M 15.403,26.918 C 15.957,27.333 16.488,27.795 16.996,28.303 L 16.096,29.48 C 15.587,28.834 15.033,28.28 14.433,27.818 L 15.402,26.918 M 15.679,31.697 16.788,32.459 C 16.233,34.352 15.425,36.176 14.363,37.931 L 13.185,37.03 C 14.247,35.321 15.079,33.544 15.679,31.697 M 18.934,22 20.25,22.277 C 20.158,22.738 20.019,23.177 19.835,23.593 H 25.237 V 24.839 H 19.281 L 18.657,25.878 C 18.472,26.248 18.172,26.64 17.757,27.056 L 16.925,26.087 C 17.802,25.025 18.472,23.663 18.933,22 M 18.587,26.295 H 24.959 C 24.959,27.726 24.936,29.065 24.89,30.312 H 25.791 V 31.559 H 24.821 C 24.728,32.529 24.659,33.475 24.613,34.399 H 25.652 V 35.576 H 24.475 C 24.29,37.192 23.643,38 22.535,38 22.258,38 21.866,37.954 21.358,37.862 L 21.15,36.684 C 21.75,36.777 22.212,36.823 22.535,36.823 22.858,36.823 23.066,36.407 23.159,35.576 H 17.756 C 17.941,34.329 18.102,32.99 18.241,31.559 H 17.271 V 30.312 H 18.379 C 18.472,29.019 18.541,27.68 18.587,26.295 M 19.626,30.312 H 23.574 C 23.62,29.342 23.643,28.396 23.643,27.472 H 19.834 C 19.788,28.488 19.718,29.435 19.626,30.312 M 21.358,27.819 C 21.866,28.142 22.327,28.511 22.743,28.927 L 21.912,29.966 C 21.496,29.504 21.035,29.088 20.527,28.719 L 21.358,27.818 M 23.297,34.399 C 23.389,33.429 23.459,32.482 23.505,31.559 H 19.557 C 19.465,32.575 19.349,33.521 19.211,34.399 H 23.297 M 21.15,31.905 C 21.704,32.228 22.212,32.598 22.674,33.013 L 21.773,34.052 C 21.312,33.544 20.827,33.106 20.319,32.736 L 21.15,31.905 M 13.877,23.663 V 34.537 H 12.63 V 33.359 H 11.453 V 35.16 H 10.206 V 23.662 H 13.877 M 11.453,32.182 H 12.63 V 24.84 H 11.453 V 32.182"/>
<path style="opacity:0.2" d="M 4,42 V 43 C 4,44.108 4.892,45 6,45 H 32 V 44 H 6 C 4.892,44 4,43.108 4,42 Z"/>
<path style="fill:#a3a3a3" d="M 16,32 32,44 V 20 L 16,4 Z"/>
<path style="opacity:0.2;fill:#ffffff" d="M 6,16 C 4.892,16 4,16.892 4,18 V 19 C 4,17.892 4.892,17 6,17 H 32 V 16 Z"/>
<path style="fill:#2095f2" d="M 16,4 V 32 H 42 C 43.108,32 44,31.108 44,30 V 6 C 44,4.892 43.108,4 42,4 Z"/>
<path style="fill:#ffffff" d="M 28.221,19.374 28.614,17.902 C 29.055,16.306 29.473,14.441 29.865,12.748 H 29.963 C 30.381,14.417 30.822,16.306 31.264,17.902 L 31.632,19.374 H 28.221 M 33.349,26 H 37.177 L 32.171,10 H 27.828 L 22.821,26 H 26.502 L 27.484,22.196 H 32.367 L 33.349,26"/>
<path style="opacity:0.2" d="M 44,30 C 44,31.108 43.108,32 42,32 H 16 V 33 H 42 C 43.108,33 44,32.108 44,31 Z"/>
<path style="opacity:0.2;fill:#ffffff" d="M 16,4 V 5 H 42 C 43.108,5 44,5.892 44,7 V 6 C 44,4.892 43.108,4 42,4 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@@ -0,0 +1,201 @@
-------------------------------------------------
-- Translate Widget based on the Yandex.Translate API
-- https://tech.yandex.com/translate/
-- @author Pavel Makhov
-- @copyright 2020 Pavel Makhov
-------------------------------------------------
local awful = require("awful")
local spawn = require("awful.spawn")
local capi = {keygrabber = keygrabber }
local beautiful = require("beautiful")
local json = require("json")
local naughty = require("naughty")
local wibox = require("wibox")
local gears = require("gears")
local gfs = require("gears.filesystem")
local TRANSLATE_CMD = [[bash -c 'curl -s -u "apikey:%s" -H "Content-Type: application/json"]]
..[[ -d '\''{"text": ["%s"], "model_id":"%s"}'\'' "%s/v3/translate?version=2018-05-01"']]
local ICON = os.getenv("HOME") .. '/.config/awesome/awesome-wm-widgets/translate-widget/gnome-translate.svg'
--- Returns two values - string to translate and direction:
-- 'dog enfr' -> 'dog', 'en-fr'
-- @param input_string user's input which consists of
-- text to translate and direction, 'dog enfr'
local function extract(input_string)
local word, lang = input_string:match('^(.+)%s(%a%a%a%a)$')
if word ~= nil and lang ~= nil then
lang = lang:sub(1, 2) .. '-' .. lang:sub(3)
end
return word, lang
end
local function show_warning(message)
naughty.notify{
preset = naughty.config.presets.critical,
title = 'Translate Shell',
text = message}
end
local w = awful.popup {
widget = {},
visible = false,
border_width = 1,
maximum_width = 400,
width = 400,
border_color = '#66ccff',
ontop = true,
bg = beautiful.bg_normal,
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 3)
end,
}
awful.placement.top(w, { margins = {top = 40}})
--- Main function - takes the user input and shows the widget with translation
-- @param request_string - user input (dog enfr)
local function translate(to_translate, lang, api_key, url)
local cmd = string.format(TRANSLATE_CMD, api_key, to_translate, lang, url)
spawn.easy_async(cmd, function (stdout, stderr)
if stderr ~= '' then
show_warning(stderr)
end
local resp = json.decode(stdout)
w:setup {
{
{
{
{
image = ICON,
widget = wibox.widget.imagebox,
resize = false
},
valign = 'center',
layout = wibox.container.place,
},
{
{
id = 'src',
markup = '<b>' .. lang:sub(1,2) .. '</b>: <span color="#FFFFFF"> '
.. to_translate .. '</span>',
widget = wibox.widget.textbox
},
{
id = 'res',
markup = '<b>' .. lang:sub(4) .. '</b>: <span color="#FFFFFF"> '
.. resp.translations[1].translation .. '</span>',
widget = wibox.widget.textbox
},
id = 'text',
layout = wibox.layout.fixed.vertical,
},
id = 'left',
spacing = 8,
layout = wibox.layout.fixed.horizontal
},
bg = beautiful.bg_normal,
forced_width = 400,
widget = wibox.container.background
},
color = beautiful.bg_normal,
margins = 8,
widget = wibox.container.margin
}
w.visible = true
w:buttons(
awful.util.table.join(
awful.button({}, 1, function()
spawn.with_shell("echo '" .. resp.translations[1].translation .. "' | xclip -selection clipboard")
w.visible = false
end),
awful.button({}, 3, function()
spawn.with_shell("echo '" .. to_translate .."' | xclip -selection clipboard")
w.visible = false
end)
)
)
capi.keygrabber.run(function(_, key, event)
if event == "release" then return end
if key then
capi.keygrabber.stop()
w.visible = false
end
end)
end)
end
local prompt = awful.widget.prompt()
local input_widget = wibox {
visible = false,
width = 300,
height = 100,
maxmimum_width = 300,
maxmimum_height = 900,
ontop = true,
screen = mouse.screen,
expand = true,
bg = beautiful.bg_normal,
max_widget_size = 500,
border_width = 1,
border_color = '#66ccff',
shape = function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, 3)
end,
}
input_widget:setup{
{
prompt,
bg = beautiful.bg_normal,
widget = wibox.container.background
},
margins = 8,
widget = wibox.container.margin
}
local function launch(user_args)
local args = user_args or {}
local api_key = args.api_key
local url = args.url
awful.placement.top(input_widget, { margins = {top = 40}, parent = awful.screen.focused()})
input_widget.visible = true
awful.prompt.run {
prompt = "<b>Translate</b>: ",
textbox = prompt.widget,
history_path = gfs.get_dir('cache') .. '/translate_history',
bg_cursor = '#66ccff',
exe_callback = function(text)
if not text or #text == 0 then return end
local to_translate, lang = extract(text)
if not to_translate or #to_translate==0 or not lang or #lang == 0 then
naughty.notify({
preset = naughty.config.presets.critical,
title = 'Translate Widget Error',
text = 'Language is not provided',
})
return
end
translate(to_translate, lang, api_key, url)
end,
done_callback = function()
input_widget.visible = false
end
}
end
return {
launch = launch
}