wip
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
#!/usr/bin/env nodejsscript
|
||||
/* jshint esversion: 11,-W097, -W040, module: true, node: true, expr: true, undef: true *//* global echo, $, pipe, s, fetch, cyclicLoop */
|
||||
|
||||
const pathLastDesktop= ()=> $.xdg.temp`kde6-workarounds-last-desktop.txt`;
|
||||
const css= echo.css`
|
||||
.code { color: gray; }
|
||||
`;
|
||||
|
||||
$.api()
|
||||
.version("2024-02-29")
|
||||
.describe("Workarounds for KDE6.")
|
||||
.command("logout")
|
||||
.action(function(){
|
||||
$.is_silent= true;
|
||||
const res= s.run([
|
||||
"echo ::options::",
|
||||
"|",
|
||||
"rofi -dmenu -p 'Logout' -l 4 -theme-str 'window { width: 25ch; }' -normal-window"
|
||||
].join(" "), {
|
||||
options: [ "-", "poweroff", "reboot" ].join("\n")
|
||||
}).trim();
|
||||
if(res && res!=="-") s.run(res);
|
||||
$.exit(0);
|
||||
})
|
||||
.command("klipper-edit", "Edit last item in klipper.")
|
||||
.action(async function(){
|
||||
$.is_silent= true;
|
||||
const qdbus= "qdbus org.kde.klipper /klipper org.kde.klipper.klipper.";
|
||||
try{
|
||||
const candidate= s.run(`${qdbus}getClipboardContents`).trim();
|
||||
const content= await $.read({ "-p": "Edit", completions: [ candidate ] });
|
||||
s.run(`${qdbus}setClipboardContents "${content}"`);
|
||||
$.exit(0);
|
||||
} catch (_){
|
||||
$.exit(1);
|
||||
}
|
||||
})
|
||||
.command("desktops-alttab", "Workaround for KDE6 alt-tab between virtual desktops.")
|
||||
.action(function(){
|
||||
const path= pathLastDesktop();
|
||||
// Regarding ★ : this is a workaround for diagonal switching (it duplicates desktop index)
|
||||
let desktop= s.cat(path).trim() || "1";
|
||||
if(desktop.length>3){ // ★
|
||||
const [ _1, _2, ..._3 ]= desktop.slice(-4, desktop.length);
|
||||
if(_1===_2)
|
||||
desktop= desktop.slice(0, -4).concat(_1, ..._3);
|
||||
}
|
||||
if(desktop.length>2){ // ★
|
||||
const [ _1, _2 ]= desktop.slice(-2, desktop.length);
|
||||
if(_1===_2)
|
||||
desktop= desktop.slice(0, -1);
|
||||
}
|
||||
if(desktop.length>2){
|
||||
desktop= desktop.slice(-2, desktop.length);
|
||||
s.echo(desktop).to(path);
|
||||
}
|
||||
echo(desktop);
|
||||
s.run`qdbus org.kde.KWin /KWin org.kde.KWin.setCurrentDesktop ${desktop[0]}`;
|
||||
$.exit(0);
|
||||
})
|
||||
.command("desktops-last-dbus")
|
||||
.action(function(){
|
||||
echo([
|
||||
"dbus-monitor",
|
||||
'"interface=org.kde.KWin.VirtualDesktopManager" "member=currentChanged"',
|
||||
"|",
|
||||
'xargs -e -I {} kde6-workarounds.mjs desktops-last-save {}'
|
||||
].join(" "));
|
||||
$.exit(0);
|
||||
})
|
||||
.command("desktops-last-save <dbus>", "Workaround for KDE6 alt-tab between virtual desktops.")
|
||||
.action(function(dbus){
|
||||
if(-1===dbus.indexOf("path=/VirtualDesktopManager; interface=org.kde.KWin.VirtualDesktopManager; member=currentChanged"))
|
||||
return $.exit(1);
|
||||
const desktop= s.run`qdbus org.kde.KWin /KWin org.kde.KWin.currentDesktop`.trim();
|
||||
s.echo(desktop).toEnd(pathLastDesktop());
|
||||
})
|
||||
.parse();
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eou pipefail
|
||||
dbus-monitor "interface=org.kde.KWin.VirtualDesktopManager" "member=currentChanged" | xargs -e -I {} kde6-workarounds.mjs desktops-last-save {}
|
||||
@@ -1 +0,0 @@
|
||||
/home/jaandrle/.local/share/pipx/venvs/ra-aid/bin/ra-aid
|
||||
@@ -1,94 +0,0 @@
|
||||
#!/usr/bin/env nodejsscript
|
||||
/* jshint esversion: 11,-W097, -W040, module: true, node: true, expr: true, undef: true *//* global echo, $, pipe, s, style, fetch, cyclicLoop, xdg, $ */
|
||||
import { basename } from "path";
|
||||
const app= {
|
||||
name: basename(process.argv[1]),
|
||||
version: "2022-09-28",
|
||||
cmd: $.xdg.home`.local/bin/himalaya`,
|
||||
configs: $.xdg.config`himalaya/`,
|
||||
modificator: "§"
|
||||
};
|
||||
const chars= { "&AOE-": "á", "&AWE-": "š", "&ARs-": "ě" };
|
||||
let argv_arr= argvArr();
|
||||
|
||||
if("help"===argv_arr.toString().replaceAll("-", "")){ //#region
|
||||
echo([ `${app.name}@${app.version}`,
|
||||
`This is small wrapper around 'himalaya' fixing coding errors and provide better 'read'. (Use § for calling himalaya directly)`,
|
||||
"" ].join("\n"));
|
||||
s.run(app.cmd+" --help");
|
||||
$.exit(0); //#endregion
|
||||
}
|
||||
if("version"===argv_arr.toString().replaceAll("-", "")){//#region
|
||||
echo(`${app.name} ${app.version}`);
|
||||
s.run(app.cmd+" --version");
|
||||
$.exit(0);//#endregion
|
||||
}
|
||||
if("completion,bash"===argv_arr.toString()){//#region
|
||||
const completion= s.run(app.cmd+" ::argv_arr::", { argv_arr });
|
||||
echo(completion.toString().replace("himalaya)", `himalaya|${app.name})`));
|
||||
echo(`alias ${app.name}-inbox="§mail § | less -R -S"`);
|
||||
echo(`complete -F _himalaya -o bashdefault -o default ${app.name}`);
|
||||
$.exit(0);//#endregion
|
||||
}
|
||||
(async function main(){
|
||||
if(argv_arr.indexOf(app.modificator)!==-1) await runH(argv_arr.filter(l=> l!==app.modificator));
|
||||
|
||||
argv_arr= argv_arr.filter(str=> str!==app.modificator);
|
||||
if(argv_arr.indexOf("list")!==-1){
|
||||
argv_arr.push("-w", process.stdout.columns);
|
||||
await runH(argv_arr);
|
||||
}
|
||||
if(argv_arr.indexOf("read")!==-1){
|
||||
const email= $.xdg.temp`/himalaya-read.eml`;
|
||||
argv_arr.push("-h", "From", "-h", "Subject");
|
||||
await s.$().runA(app.cmd+" ::argv_arr::", { argv_arr }).pipe(s=> s.to(email));
|
||||
await s.runA`vim ${email}`.pipe(process.stdout);
|
||||
$.exit(0);
|
||||
}
|
||||
|
||||
if(argv_arr[0] && argv_arr[0]!=="--rofi") await runH(argv_arr);
|
||||
|
||||
const template_path= app.configs+"template-inbox.json";
|
||||
if(!s.test("-f", template_path)) await runH([]);
|
||||
|
||||
const out= await pipe(
|
||||
f=> s.cat(f).xargs(JSON.parse),
|
||||
argv_arr.indexOf('--rofi')===-1 ? templateRead : templateRofi,
|
||||
a=> Promise.all(a)
|
||||
)(template_path);
|
||||
for(const l of out){
|
||||
if(typeof l=="string"&&!l.indexOf("%c===\n")) echo(l, "unset:all", "color:magenta");
|
||||
else echo(l);
|
||||
}
|
||||
$.exit(0);
|
||||
})();
|
||||
|
||||
function templateRofi(lines){
|
||||
return lines.filter(line=> line.type!=="text")
|
||||
.map(line=>
|
||||
s.$().runA(app.cmd+" ::value:: -w 120", line)
|
||||
.then(data=> data.toString().split("\n")
|
||||
.filter(l=> l)
|
||||
.map(line=> line.replaceAll("✷ ", "* "))
|
||||
.map(line_result=> line_result+" │ "+line.label)
|
||||
.join("\n"))
|
||||
);
|
||||
}
|
||||
function templateRead(lines){
|
||||
argv_arr.push("-w", process.stdout.columns);
|
||||
return lines.map(line=> line.type==="text" ?
|
||||
Promise.resolve("%c===\n%c"+line.value) :
|
||||
s.$().runA(app.cmd+" ::value:: ::argv_arr::", { value: line.value, argv_arr })
|
||||
);
|
||||
}
|
||||
|
||||
function argvArr(){
|
||||
const _chars= Object.entries(chars).reduce((acc, [ key, val ])=> Reflect.set(acc, val, key) && acc, {});
|
||||
return process.argv.slice(2).map(str=> str.replace(new RegExp(`(${Object.keys(_chars).join("|")})`, "g"), l=> _chars[l]));
|
||||
}
|
||||
async function runH(args){
|
||||
const result= await s.runA(app.cmd+" ::args::", { args }).pipe(process.stdout);
|
||||
$.exit(result.exitCode);
|
||||
}
|
||||
// vim: set tabstop=4 shiftwidth=4 textwidth=250 noexpandtab ft=javascript :
|
||||
// vim>60: set foldmethod=marker foldmarker=#region,#endregion :
|
||||
@@ -13,6 +13,17 @@ $.api()
|
||||
.option("--debug", "Debug mode")
|
||||
.option("--force", "Overwrite output file.")
|
||||
|
||||
.command("metaFromFrontmatter <name-input>", "Print metadata from frontmatter as `--metadata …` to be used with `pandoc`.")
|
||||
.alias("meta")
|
||||
.action(function metaFromFrontmatterCMD(input){
|
||||
const metadata= frontmatterToDict(s.cat(input).trim());
|
||||
let metadata_str= [];
|
||||
for(const [ key, value ] of Object.entries(metadata))
|
||||
metadata_str.push(`--metadata ${key}="${value}"`);
|
||||
echo(metadata_str.join(" "));
|
||||
$.exit(0);
|
||||
})
|
||||
|
||||
.command("to-html <name-input> [name-output]", "Convert markdown to html.")
|
||||
.alias("tohtml")
|
||||
.action(function tohtmlCMD(input, output, options){
|
||||
@@ -87,6 +98,20 @@ function tempFileGenerator(orig){
|
||||
const basename= orig.slice(basepath.length, orig.lastIndexOf("."));
|
||||
return ext=> basepath+"."+basename+"-"+nameHash()+ext;
|
||||
}
|
||||
function frontmatterToDict(content){
|
||||
const dict= {};
|
||||
if(!content.startsWith("---"))
|
||||
return dict;
|
||||
for(const line_raw of content.split("\n").slice(1)){
|
||||
const line= line_raw.trim();
|
||||
if(!line) continue;
|
||||
if(line==="---") break;
|
||||
const [key_raw, value]= line.split(/: */);
|
||||
let key= key_raw.replace(/^-+/, "");
|
||||
dict[key]= value;
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {(ext: string)=> string} tempFile
|
||||
@@ -97,16 +122,10 @@ function prepareInput(input, tempFile){
|
||||
const content= s.cat(input).trim();
|
||||
let input_data= {};
|
||||
echo(" extract input metadata and eval `~` to $HOME (CSS)");
|
||||
if(content.startsWith("---"))
|
||||
for(const line_raw of content.split("\n").slice(1)){
|
||||
const line= line_raw.trim();
|
||||
if(!line) continue;
|
||||
if(line==="---") break;
|
||||
const [key_raw, value]= line.split(/: */);
|
||||
let key= key_raw.replace(/^-+/, "");
|
||||
key= key[0].toUpperCase()+key.slice(1);
|
||||
input_data[key]= value;
|
||||
}
|
||||
for(const [ key, value ] of Object.entries(frontmatterToDict(content))){
|
||||
key= key[0].toUpperCase()+key.slice(1);
|
||||
input_data[key]= value;
|
||||
}
|
||||
s.echo(content.replaceAll("file:///~", "file:///"+process.env.HOME)).to(input_tmp);
|
||||
return { input_tmp, input_data };
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ const css= echo.css`
|
||||
`;
|
||||
|
||||
$.api()
|
||||
.version("2023-04-18")
|
||||
.version("2026-03-16")
|
||||
.describe([
|
||||
"Utility for managing vim plugins “native” way. It uses two types:",
|
||||
`- “old” way (${f("bundle", css.code)}): inspiration from ${f("https://shapeshed.com/vim-packages/", css.url)}`,
|
||||
@@ -275,7 +275,7 @@ function echoProgress(length, message_start= "Working"){
|
||||
};
|
||||
}
|
||||
|
||||
function getPack(){ return s.ls(dirs.pack).flatMap(f=> s.find(dirs.pack+f+"/start/*/")[0]).filter(Boolean); }
|
||||
function getPack(){ return s.ls("-l", dirs.pack).filter(e=> e.isDirectory()).map(e=> e.name).flatMap(f=> s.find(dirs.pack+f+"/start/*/")[0]).filter(Boolean); }
|
||||
function getBundle(){ return s.cd(dirs.bundle).grep("path", ".gitmodules").split("\n").filter(Boolean).map(l=> dirs.bundle+l.split(" = ")[1]); }
|
||||
function getOneFiles(){ return s.find(dirs.one_files+"*"); }
|
||||
function getOneFilesUrls(){ return s.cat(file_one_file).xargs(JSON.parse); }
|
||||
|
||||
Reference in New Issue
Block a user