Skip to content

Instantly share code, notes, and snippets.

@zfenj
zfenj / brightnessControl.sh
Created September 29, 2019 19:12 — forked from Blaradox/brightnessControl.sh
Notifications for brightness and volume, using dunstify
#!/usr/bin/env bash
# You can call this script like this:
# $ ./brightnessControl.sh up
# $ ./brightnessControl.sh down
# Script inspired by these wonderful people:
# https://github.com/dastorm/volume-notification-dunst/blob/master/volume.sh
# https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a
@zfenj
zfenj / .aliases
Created August 29, 2019 07:36 — forked from alekratz/.aliases
Pacman aliases
# pacman aliases
alias pac='pacman -S' # install
alias pacu='pacman -Syu' # update, add 'a' to the list of letters to update AUR packages if you use yaourt
alias pacr='pacman -Rs' # remove
alias pacs='pacman -Ss' # search
alias paci='pacman -Si' # info
alias paclo='pacman -Qdt' # list orphans
alias pacro='paclo && sudo pacman -Rns $(pacman -Qtdq)' # remove orphans
alias pacc='pacman -Scc' # clean cache
alias paclf='pacman -Ql' # list files
@zfenj
zfenj / ask.sh
Created July 12, 2019 10:41
Bash General-Purpose Yes/No Prompt Function ("ask")
# This is a general-purpose function to ask Yes/No questions in Bash, either
# with or without a default answer. It keeps repeating the question until it
# gets a valid answer.
ask() {
# https://gist.github.com/davejamesmiller/1965569
local prompt default reply
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
# Source: https://unix.stackexchange.com/a/115431
#!/usr/bin/env zsh
# only file- / script name
echo ${0:a}
#!/usr/bin/env zsh
# file- / script name with path
echo ${0:a:h}
@zfenj
zfenj / gist:30d6fe55de03823d87627fd23d8c60c4
Created May 11, 2019 19:07
ZSH string manipulation: split string
# https://bougui505.github.io/2016/02/29/zsh_string_manipulation-_split_string.html
Split string in a given word separator (ws)
For example _:
# x="foo_1"
# echo $x[(ws:_:)1]
foo
# echo $x[(ws:_:)2]
1
@zfenj
zfenj / gist:43dc107ab0685343d558d2c8024081fd
Last active November 9, 2022 22:25
Zsh: Get Filename or Extension from Path
# https://zaiste.net/zsh_get_filename_extension_path/#!/bin/zsh
# Filename
fullpath="/etc/nginx/nginx.conf"
filename=$fullpath:t
echo $filename
nginx.conf
# Path
fullpath="/etc/nginx/nginx.conf"
@zfenj
zfenj / Has weird right-to-left characters.txt
Created March 10, 2019 18:27 — forked from endolith/Has weird right-to-left characters.txt
Unicode kaomoji smileys emoticons emoji
ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶
@zfenj
zfenj / git_repo_info.py
Created March 3, 2019 19:35 — forked from Brimizer/git_repo_info.py
GitPython get current active branch
"""
Depends on GitPython
pip install GitPython
"""
from git import Repo
def get_current_branch_name(repo_path)
"""
Gets the name of the active Git branch as a string.
Bash: How to output command to next prompt for user to use?
Source: https://superuser.com/a/1130773
MY_COMMAND="ls"
MY_PARAMS=()
read -a MY_PARAMS -p $MY_COMMAND
exec $MY_COMMAND ${MY_PARAMS[@]}
@zfenj
zfenj / gist:0307145f652a2b18398094e0f86076e6
Created January 13, 2019 15:03
xdotool: reload (second) browser window
# test: get ids of all open browser windows
wins=$(xdotool search --screen 0 --onlyvisible --class "qutebrowser")
echo $wins
# > 16777247
# > 16785319
# > 16786158
# get id of second window
win=$(xdotool search --screen 0 --onlyvisible --class "qutebrowser" | head -2 | tail -1)