Skip to content

Instantly share code, notes, and snippets.

@miyl
miyl / hyprland-monitor-toggle.sh
Last active November 10, 2024 15:33
A hyprland script for a laptop-external-monitor setup, toggling between which is in use
#! /usr/bin/env sh
# A hyprland script for a laptop-external-monitor setup, toggling between which is in use
# Launch at startup to make hyprland disable the internal monitor if an external monitor is detected and enabled
# Additionally it's called with a keybind to switch between a laptop monitor and an external display
# Ideally the conditional monitor behaviour was instead done directly in hyprland.conf, but I'm not sure whether that's possible
#
# Relevant info:
# - hyprctl monitors: identifies currently enabled monitors
@miyl
miyl / mim.sh
Last active June 15, 2024 19:37
Screenshot utility script for binding to PrintScreen, using grim and slurp under the hood
#! /usr/bin/env sh
# Screenshot program wrapper, pre-setting path.
# Allows you to select whether to save to disk or copy to clipboard, and additionally whether to select an area or
# capture the full screen.
#
# Suggested usage:
# Make a keybind for it, such as the PrintScreen key.
#
# Prerequisites:
@miyl
miyl / pipewire-in-default-switch.sh
Last active April 1, 2024 19:52
Pipewire default source (input) switching (Pulseaudio pactl)
#!/usr/bin/env sh
# This script switches between whatever sources exist.
# Removing pulseaudio (but not libpulse) means removing pacmd, so this is an attempt at switching the default via pactl instead.
# Cycles through all sources and sets whatever is the next one as the default.
# Pass -g to just print the current default source
CUR_DEFAULT="$(pactl info | grep 'Default Source' | cut -d':' -f 2)"
SOURCES="$(pactl list short sources | cut -d' ' -f 2)"
@miyl
miyl / pipewire-out-default-switch.sh
Last active October 17, 2024 02:19
Pipewire default sink (output) switching (Pulseaudio pactl)
#! /usr/bin/env sh
# This script switches between whatever sinks exist.
# Removing pulseaudio (but not libpulse) means removing pacmd, so this is an attempt at switching the default via pactl instead.
# Sinks can be specified by name or index. Index changes sometimes when you disconnect and reconnect, restart or whatever, so names are better as they are persistent.
# Annoyingly the command used to switch audio over to a new sink cannot take a name as its argument, otherwise I'd only need the name here.
# TODO: Trigger a zenity or dmenu dialog with entr that asks whether to switch monitor and/or sound to hdmi? Could do
# the same for mounting.
@miyl
miyl / git-checkout-fzf.sh
Last active March 28, 2024 18:27
Improve checking out branches in git via fzf
# Description:
# 1. Check if inside git repository.
# 2. If so list all branches except the current including its remote equivalent.
# 3. Remove duplicates that are both local and remote.
# 4. Send it to fzf, and checkout the branch chosen from there.
git config --global alias.co '! git rev-parse --is-inside-work-tree > /dev/null 2>&1 && git branch -a | sed -e "\,HEAD\|$(git branch --show-current),d" | sed "s,remotes/origin/,," | sort | uniq | fzf | xargs -r git checkout'
# Here's a cowsay/lolcat version for the adventurous:
# git config --global alias.co '! a=$(git rev-parse --is-inside-work-tree > /dev/null 2>&1 && git branch -a | sed -e "\,HEAD\|$(git branch --show-current),d" | sed "s,remotes/origin/,," | sort | uniq | fzf | xargs -r git checkout); [ -n "$a" ] && echo "$a" | cowsay -n | lolcat'
@miyl
miyl / cd.sh
Last active March 18, 2021 18:40
Intelligent cd
# /usr/bin/env sh
# You've heard of exa/lsd, sd and fd. But what about a modern cd?
# This isn't really it. Try autojump/z/fasd?
# But maybe this does make plain old cd 5% better, on a good day?
# Description: Just a vaguely intelligent cd
# Specifically it can handle cd'ing to a path even if it has a filename
# at the end, in which case it cd's to the directory which contains it
@miyl
miyl / rasmus-pandekage.txt
Last active May 12, 2020 15:13
Rasmus Pandekage
// ==UserScript==
// @name Rasmus Pandekage
// @namespace rasmuspandekage
// @include *
// @version 0.2
// ==/UserScript==
// Just the source for the Chrome extension Rasmus Pandekage by tykfyr,
// so you can easily add it as a script for GreaseMonkey or Tampermonkey, including in other browsers than Chrome.
// Original extension link: https://chrome.google.com/webstore/detail/rasmus-pandekage/pfhcceonfnhnmmfgkeblckhfphmiiafi?hl=da
@miyl
miyl / samuelsen.py
Created October 16, 2018 23:22
Samuelsen
# Origin: https://www.facebook.com/AndersSamuelsenLA/posts/10157429519542366
import random
nouns = ["kærlighed", "tro", "håb", "fællesskab", "glæde", "lykke", "lyksaglighed", "salighed", "smidighed", "fleksibilitet", "ekstase"]
#se = ["fremad", "videre", "længere"]
adverbs = ["bedre", "hurtigere", "kærligere", "rarere", "blødere", "smukkere", "pænere", "frækkere", "flottere", "finere", "ædlere", "højere", "smartere"]
def a():
elem = random.choice(adverbs)
adverbs.remove(elem)
@miyl
miyl / iw_scan.awk
Created April 7, 2016 12:37
simplify the output of iw scan
# Based off this answer http://stackoverflow.com/a/17880517/1172409
# Ideally one wouldn't parse the output of iw scan (it may be subject to change),
# but dealing with learning libnl which iw uses seems overly complicated - more so than updating this in case iw does change.
# A few things that could be improved:
# Better padding solution for prettier pretty printing.
# Sort APs based off signal strength from best to worst.
# Usage - iw must be run as root (suggestion: add as an alias in bashrc):
# iw wlp8s0 scan | awk -f scan.awk

Keybase proof

I hereby claim:

  • I am miyalys on github.
  • I am miyalys (https://keybase.io/miyalys) on keybase.
  • I have a public key whose fingerprint is 8F17 AD08 3D5A 002F FEB9 14C5 BACE FC9A 881E 2EB5

To claim this, I am signing this object: