Skip to content

Instantly share code, notes, and snippets.

View marendowski's full-sized avatar

Piotr Marendowski marendowski

View GitHub Profile
@marendowski
marendowski / efi.sh
Created March 2, 2024 17:57
Arch Linux EFISTUB script
#!/usr/bin/env bash
# Creates an EFI boot option for kernel image on the root partition with swap included
# Requires: efibootmgr, blkid
# Kernel parameters are after '--unicode'
root_uuid="$(blkid -s UUID -o value /dev/nvme0n1p3)"
swap_uuid="$(blkid -s UUID -o value /dev/nvme0n1p2)"
efibootmgr --create --disk /dev/nvme0n1 --part 1 --label "Arch Linux" --loader /vmlinuz-linux --unicode "root=UUID=${root_uuid} resume=UUID=${swap_uuid} rw initrd=\initramfs-linux.img"
@marendowski
marendowski / smartborders-2023-12-07.patch
Last active December 7, 2023 14:01
Smartborders patch for dwl (2023-12-07)
From ee4887ce283d44bb1fa63cdf714b6d41a9dfe2d6 Mon Sep 17 00:00:00 2001
From: Piotr Marendowski <[email protected]>
Date: Thu, 7 Dec 2023 14:14:00 +0100
Subject: [PATCH] Fix smartborders patch
---
config.def.h | 1 +
dwl.c | 42 +++++++++++++++++++++++++++---------------
2 files changed, 28 insertions(+), 15 deletions(-)
@marendowski
marendowski / dmenu-history.sh
Last active October 30, 2023 18:27
Run dmenu with history of launched programs
#!/bin/sh
# default history path = ~/.cache/
cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
histsize=50 # size of the history file
cache=$cachedir/dmenu
hist=$cachedir/dmenu_history
# if there isn't a history file - create it
if [ ! -e "$hist" ]; then
touch "$hist"
echo foo
@marendowski
marendowski / dmenu-translate.sh
Created October 29, 2023 14:24
Use google translate to translate words or sentences using dmenu
#!/bin/sh
cmd=$(dmenu_path | dmenu "$@")
case $cmd in
# translate e.g. `en:es hello world` -> translate hello world to spanish
*:* ) lang1=$(echo $cmd | cut -d':' -f1);
lang2=$(echo $cmd | cut -d':' -f2 | cut -d' ' -f1);
query=$(echo $cmd | cut -d':' -f2 | awk '{for(i=2;i<=NF;i++) print $i}'); # get query after `es:en `
query=$(echo $query | sed -E 's/\s{1,}/\+/g'); # substitute spaces for `+`
@marendowski
marendowski / dmenu.sh
Last active October 21, 2023 19:45
Run commands using dmenu in st terminal
#!/bin/sh
# run commands in dmenu by adding ! at the end
# otherwise runs selected program
cmd="$(dmenu_path | dmenu -p "Run >" $@)"
case $cmd in
*\! ) cmd=$(printf "%s" "${cmd}" | cut -d'!' -f1);
st -e sh -c "${cmd};exec $SHELL";;
* ) ${cmd} ;;
esac
@marendowski
marendowski / xlib-png-demo.c
Created July 27, 2023 13:17
C demo displaying a PNG image on X server using Xlib and libspng libraries
/* requires Xlib and libspng *
* gcc -o demo demo.c -l X11 -l spng -g */
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#include <spng.h>
unsigned char *process_png_image(char *filename);
int main(void)