Skip to content

Instantly share code, notes, and snippets.

@tcely
tcely / config
Created September 8, 2023 14:28
Turn on ssh-rsa for only the hosts that require that option
# Add this to the ~/.ssh/config file
#
Match Exec "ssh-rsa-needed.sh '%n' '%C' '%l' '%h' '%p' '%r'"
PubkeyAcceptedKeyTypes +ssh-rsa
@tcely
tcely / history.inc.sh
Last active August 24, 2023 20:33
Bash History Configuration
if [ "${BASH_VERSION-}" ]; then
# Local variables the functions depend upon
_bash_history_prefix=~/.local/history/bash
# {{{ Begining of the temporary functions block
_bash_history_get_today() {
date '+%Y/0%m/%d'
}
@tcely
tcely / Social_Media.md
Created December 18, 2022 23:04
Social Media Information
@tcely
tcely / simple-echo.function.sh
Created September 22, 2020 00:04
A simple echo using the shell printf for consistent behavior
#!/usr/bin/env sh
secho() {
_arg="${1}";
_fmt='%s';
_sentinel='--';
case "${_arg}" in
(-e|-en|-ne) _fmt='%b'; shift ;;
(-n|-En|-nE) shift ;;
@tcely
tcely / README.md
Last active June 26, 2019 00:21
AlpineLinux aports style decisions
  1. Shell (ash from busybox) variables are always quoted and use curly braces.

    "Optimize for the inexperience newcomers rather than the experience gurus." As explained in this post there are a few quirks when dealing with shell variables that do not use the curly braces. For example: $pkgver

    Instead of expecting new contributors to already know about all of the pitfalls involved with using that syntactic sugar, it is better to just always use the braces. Shell variables are quoted when assigned and used, when accessed they are quoted and surrounded by curly braces. For example: pkgname='bind' or pkgdesc="${pkgname} tools" and "${pkgname}"

The characters that do and do not extend the name of the variable are not a concern when the intention of what the variable name should be is made clear by using this explicit syntax. Users don't need to remember which of _, -, or . will change the variable name and lead to an empty value be

#!/bin/sh
github_email_to_login() {
local url='https://api.github.com/search/users'
local filter='.items|.[]|select(.type == "User")|.login'
local email="${1}"
curl -sSL "${url}?q=in:email+${email}" | jq -r "${filter}"
}
@tcely
tcely / README.md
Last active May 27, 2019 00:27
Restic "Pull" Solution

As I originally outlined in this comment there is a work around for the problem of having shared credentials and keys on the various backup "clients" so that they push their contents to your restic server.

I have implemented this solution, but it took a fair amount of work. I am putting this work up for bounty, so if you are interested please contact me to arrange payment and when the goal is reached, I will send my solution to everyone who chipped in.

Thank you very much!

@tcely
tcely / shebang.awk
Last active January 12, 2023 19:42
A good portable awk shebang is not easy to find.
#!/usr/bin/awk -f
#!/usr/bin/awk -E
#
# If you have an awk version that doesn't support the -f flag,
# then you are just out of luck.
#
# If you just have no clue where awk will be, or you prefer to use -E,
# then you can try this bash snippet to launch awk for you.
#
# You might think the -E tests below are overly complex. You'd be wrong.
@tcely
tcely / min_max.awk
Last active May 13, 2022 23:28
min & max functions for awk. I was a bit surprised these weren't already in the numeric functions section of the man page already.
#!/usr/bin/awk -f
function limit_seeker(a, b, direction) {
_record=b;
if (isarray(a)) {
for (k in a) {
_record=limit_seeker(a[k], _record, direction);
}
} else {
@tcely
tcely / conditional_get_etag.sh
Created January 16, 2018 16:35
Download a file when its ETag changes. Useful for GitHub (which doesn't respect If-Modified-Since).
#!/bin/bash
conditional_get_etag() {
local _url _file _tmpdir
local _awk_program='/^ETag:/ {$1=""; printf "If-None-Match: %s", substr($0, 2, length($0)-2); exit;}'
for _url; do
if [ '--file=' = "${_url:0:7}" ]; then
_file="${_url:7}"
continue