Skip to content

Instantly share code, notes, and snippets.

View nat-418's full-sized avatar

Nat nat-418

View GitHub Profile
@nat-418
nat-418 / expecting.md
Created January 8, 2023 15:16 — forked from ksafranski/expecting.md
Basic principles of using tcl-expect scripts

Intro

TCL-Expect scripts are an amazingly easy way to script out laborious tasks in the shell when you need to be interactive with the console. Think of them as a "macro" or way to programmaticly step through a process you would run by hand. They are similar to shell scripts but utilize the .tcl extension and a different #! call.

Setup Your Script

The first step, similar to writing a bash script, is to tell the script what it's executing under. For expect we use the following:

#!/usr/bin/expect
@nat-418
nat-418 / nix-home-manager-neovim-setup.md
Last active May 8, 2024 07:40
Manage Neovim plugins (and more!) with Nix and Home Manager

Manage Neovim plugins (and more!) with Nix and Home Manager

Highly extensible software like Emacs, Vim, and Neovim tend to grow their own package managers. A software developer, for example, might want to install editor plugins that hook into a particular programming language's linter or language server. The programmer's text editor is therefore extended to support managing additional software to extend the text editor. If this loop continues for too long, the programmer's editor becomes more delicate and complex. The remedy for this problem is to manage software using dedicated tools apart

@nat-418
nat-418 / Hyper.md
Created March 27, 2022 19:35 — forked from toroidal-code/Hyper.md
Have you a Hyper for Great Good

Have you Hyper for Great Good

So. You have become an Emacs wizard. And you find yourself aching for the simplicity that another modifier key would introduce into your life. Ah, the things you could do with Hyper.

Or maybe, you just want Hyper for another reason.

... Except everywhere you look, everyone's talking about .xmodmaps and xkbcomp, but you're using one of those fancy desktop managers. (Aka, not awesome, dwm, xmonad or something even more hipster) And because of that, you're lost in the sea of confusion that is trying to customize your keyboard mapping.

Gnome, Cinnamon, and KDE all use xkb.

@nat-418
nat-418 / hyper-key.desktop
Last active July 26, 2023 06:52
How to enable the Hyper key on Linux
[Desktop Entry]
Name[en_US]=hyper-key
Comment[en_US]=Set CapsLock to Control and Escape to Hyper
Exec=/usr/local/bin/hyper-key.sh
Icon=application-default-icon
X-GNOME-Autostart-enabled=true
Type=Application
@nat-418
nat-418 / parse-flags.tcl
Last active May 9, 2023 07:19
How to parse command-line flags in Tcl
#!/usr/bin/env tclsh
# get flag parser from the standard library (tcllib)
package require cmdline
# set version of our command-line application (this file)
set version 0.0.1
# declare what flags to parse
# format: {flag default description}
@nat-418
nat-418 / tcl-prompt-for-editor-input.sh
Created March 13, 2022 14:23
How to read user input from an interactive text editor in Tcl
#!/usr/bin/env tclsh
#
# How to read user input from an interactive text editor in Tcl
# =============================================================
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@nat-418
nat-418 / posix-prompt-for-editor-input.sh
Last active March 13, 2022 11:33
How to prompt user input from an interactive text editor in POSIX shell
#!/bin/sh
#
# How to prompt user input from an interactive text editor in POSIX shell.
# ======================================================================
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
@nat-418
nat-418 / translate.tcl
Created December 7, 2021 16:45
Wrapper script for Argos Translate
#!/bin/env tclsh
# language should be a two-character ISO code
# languages must be installed using Argos GUI
set language_codes {
ar de en es fr it zh
}
# CLI takes two arguments, ignore the rest
lassign $argv from_code to_code
@nat-418
nat-418 / table.tcl
Last active November 14, 2021 14:22
Pretty-print a list of lists as a table in Tcl
# Format a list of lists into an evently-spaced table for logging etc.
#
# @param llst List of lists to format.
# @param padding Optionally specify how many spaces to separate fields, defaults to four.
# @return String of the pretty table.
proc table {llst {padding 4}} {
set lengths [lmap each [join $llst] {string length $each}]
set longest [expr $padding + max([join $lengths ","])]
foreach lst $llst {
@nat-418
nat-418 / box.tcl
Created November 14, 2021 13:16
Draw a pretty UTF-8 box around some text in Tcl
# Draw a UTF-8 box around some text. Useful for pretty-printing, logging, etc.
#
# @param str String to draw box around
# @return String enclosed in a fancy box
proc box str {
# Draw the top of the box
#
# @param length Number representing how long the top should be
# @return String drawing the top of the box
proc top length {