New functions/bin structure

This commit is contained in:
Ivan Malison 2021-08-02 05:18:07 -06:00
parent 2500a49c1e
commit e726ba61ae
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8
54 changed files with 313 additions and 665 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env zsh
# -*- mode:sh
hdmi_sink="$(pahelper.sh | tr -d '\\n' | tr '>' '\\n' | grep hdmi | grep -Eo ': [0-9]+' | tr -d ':')"
hdmi_sink="$(pahelper | tr -d '\\n' | tr '>' '\\n' | grep hdmi | grep -Eo ': [0-9]+' | tr -d ':')"
pahelper.sh "$hdmi_sink"
pahelper "$hdmi_sink"

View File

@ -212,9 +212,9 @@ virtualClasses =
-- Commands
gmailCommand = "start_chrome.sh --new-window https://mail.google.com/mail/u/0/#inbox"
gmailCommand = "google-chrome-stable --new-window https://mail.google.com/mail/u/0/#inbox"
spotifyCommand = "spotify"
chromeCommand = "start_chrome.sh"
chromeCommand = "start_chrome"
emacsCommand = "emacsclient -c"
htopCommand = "alacritty -e htop -t htop"
transmissionCommand = "transmission-gtk"
@ -239,9 +239,7 @@ myStartup = do
-- Manage hook
myManageHook = maybeReplaceTargetHook <+>
composeOne
[ isFullscreen -?> doFullFloat ]
myManageHook = composeOne [ isFullscreen -?> doFullFloat ]
-- Toggles
@ -656,82 +654,7 @@ focusNextClass' =
focusNextClass = sameClassOnly focusNextClass'
selectClass = join $ myDmenu <$> allClasses
-- Chrome auto minimization
data ReplaceOnNew
= NoTarget
| DontTarget
| Target Window
deriving (Typeable, Read, Show)
instance ExtensionClass ReplaceOnNew where
initialValue = NoTarget
extensionType = PersistentExtension
mapWindows f = W.mapWorkspace workspaceHelper
where
stackHelper stack = W.Stack
{ W.focus = f $ W.focus stack
, W.up = map f $ W.up stack
, W.down = map f $ W.down stack
}
workspaceHelper ws@W.Workspace {W.stack = stack} =
ws { W.stack = stackHelper <$> stack }
swapWindows a b =
mapWindows helper
where helper w
| w == a = b
| w == b = a
| otherwise = w
getTarget = do
t <- XS.get
case t of
Target w -> return $ Just w
DontTarget -> return Nothing
NoTarget -> return Nothing
maybeReplaceTarget :: Window -> X ()
maybeReplaceTarget window = do
t <- getTarget
-- We have an insertUp here to ensure the target isn't deleted
let modifyStackSet target = W.insertUp target . swapWindows window target
replaceTarget target =
windows (modifyStackSet target) >> minimizeWindow target >>
XS.put (initialValue :: ReplaceOnNew)
whenJust t replaceTarget
maybeReplaceTargetHook = ask >>= (liftX . maybeReplaceTarget) >> return (Endo id)
setReplaceTarget = withFocused $ XS.put . Target
getWindowWS a = withWindowSet $ \ws -> return $ listToMaybe
[ w | w <- W.workspaces ws, has a (W.stack w) ]
where has _ Nothing = False
has _ (Just _) = True
replaceWindow original replacement =
W.delete original . swapWindows original replacement
chromeReplaceKill =
withFocused $ \w -> do
vClass <- getClass w
if vClass == "Chrome" then
do
replacement <-
runMaybeT $ do
ws <- MaybeT $ join . fmap W.stack <$> getWindowWS w
MaybeT $
listToMaybe <$>
(intersect <$> minimizedWindows <*> windowsWithSameClass w ws)
let doReplace rep = do
maximizeWindow rep
windows $ replaceWindow w rep
maybe kill doReplace replacement
else
kill
-- Gather windows of same class
@ -874,9 +797,9 @@ goToNextScreenX = windows goToNextScreen
-- Key bindings
volumeUp = spawn "set_volume.sh --unmute --change-volume +5"
volumeDown = spawn "set_volume.sh --unmute --change-volume -5"
mute = spawn "set_volume.sh --toggle-mute"
volumeUp = spawn "set_volume --unmute --change-volume +5"
volumeDown = spawn "set_volume --unmute --change-volume -5"
mute = spawn "set_volume --toggle-mute"
shiftToEmptyOnScreen direction =
followingWindow (windowToScreen direction True) >> shiftToEmptyAndView
@ -942,9 +865,6 @@ addKeys conf@XConfig { modMask = modm } =
, ((modm, xK_x), addHiddenWorkspace "NSP" >> windows (W.shift "NSP"))
, ((modalt, xK_space), deactivateFullOr restoreOrMinimizeOtherClasses)
, ((modalt, xK_Return), deactivateFullAnd restoreAllMinimized)
, ((modm .|. controlMask, xK_t),
setReplaceTarget >> spawn "chromix-too open chrome://newtab")
, ((modm .|. controlMask, xK_c), chromeReplaceKill)
, ((hyper, xK_g), gatherThisClass)
@ -980,7 +900,6 @@ addKeys conf@XConfig { modMask = modm } =
-- Non-XMonad
, ((modm, xK_v), spawn "xclip -o | xdotool type --file -")
, ((modm .|. controlMask, xK_s), spawn "split_current_chrome_tab.sh")
, ((hyper, xK_v), spawn "rofi_clipit.sh")
, ((hyper, xK_p), spawn "rofi-pass")
, ((hyper, xK_h), spawn "screenshot.sh")
@ -992,14 +911,13 @@ addKeys conf@XConfig { modMask = modm } =
, ((hyper .|. shiftMask, xK_k),
spawn "rofi_kill_all.sh")
, ((hyper, xK_r), spawn "rofi-systemd")
, ((modalt, xK_z), spawn "split_chrome_tab_to_next_screen.sh")
, ((hyper, xK_9), spawn "start_synergy.sh")
, ((hyper, xK_slash), spawn "toggle_taffybar.sh")
, ((hyper, xK_slash), spawn "toggle_taffybar")
, ((hyper, xK_space), spawn "skippy-xd")
, ((hyper, xK_i), spawn "rofi_select_input.hs")
, ((hyper, xK_o), spawn "rofi_paswitch.sh")
, ((modm, xK_apostrophe), spawn "load_default_map.sh")
, ((modalt, xK_apostrophe), spawn "load_xkb_map.sh")
, ((hyper, xK_o), spawn "rofi_paswitch")
, ((modm, xK_apostrophe), spawn "load_default_map")
, ((modalt, xK_apostrophe), spawn "load_xkb_map")
-- Media keys

View File

@ -1,8 +0,0 @@
#!/usr/bin/env sh
dbus-send --session \
--dest=$1 \
--type=method_call \
--print-reply \
$2 \
org.freedesktop.DBus.Introspectable.Introspect | tail -n +2 | sed -e "s/^ *string//"

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
get_sink_input_info.hs | jq 'select(.application_process_id == "'"$thePID"'")'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env zsh
ip link show | grep -vE '^ ' | get_cols -F ':' 2 | xargs -n 1

View File

@ -1,20 +0,0 @@
#!/usr/bin/env bash
XKBDIR="$HOME/.xkb"
XKBMAPFILE="$XKBDIR/keymap/$(hostname --fqdn)"
[[ -r "$XKBMAPFILE" ]] || XKBMAPFILE="${XKBMAPFILE%/*}/default"
echo "loading keymap from $XKBMAPFILE"
xkbcomp -I"$XKBDIR" "$XKBMAPFILE" "${DISPLAY%%.*}"
XKB_DEVICE_DIR="$XKBDIR/devices"
for file in "$XKB_DEVICE_DIR"/*
do
DEVICE_ID=$(xinput | grep "$(basename $file)" | head -n 1 | grep -Eo "id=[0-9]*" | grep -Eo "[0-9]*")
echo $file
echo device
echo "$DEVICE_ID"
# [ ! -z "$DEVICE_ID" ] && xkbcomp -I"$XKBDIR" -i "$DEVICE_ID" "$file" "${DISPLAY%%.*}"
done

View File

@ -1,6 +1,7 @@
#!/usr/bin/env zsh
#!/usr/bin/env sh
if environment_variable_exists INSIDE_EMACS; then
emacs_pager -a less "$@"
emacsclient -n "$@"
else
less -FXr
fi

View File

@ -1,7 +0,0 @@
#!/usr/bin/env bash
encrypted_seed_file="$1"
shift
gpg --decrypt "$encrypted_seed_file" 2>/dev/null | keysmith private-key -f - -o - | quill --pem-file - "$@"

View File

@ -1,3 +0,0 @@
#!/usr/bin/env zsh
pahelper.sh | tr -d '\n' | tr '>' '|' | rofi -i -dmenu -sep '|' | grep -Eo ' [0-9]*' | xargs pahelper.sh

View File

@ -1,3 +0,0 @@
#!/usr/bin/env zsh
find ~/Pictures/wallpaper/use -type f -or -type l | rofi -i -dmenu | xargs wallpaper.sh

View File

@ -1,6 +0,0 @@
#!/usr/bin/env bash
cd "$( dirname "${BASH_SOURCE[0]}" )"
echo "$@"
stack build
stack runghc "$@"

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
XDG_CURRENT_DESKTOP='Unity' "$@"

View File

@ -1,5 +0,0 @@
#!/usr/bin/env bash
args="$(rofi -input /dev/null -dmenu)"
sleep 1
scrot $args

View File

@ -1,17 +0,0 @@
#!/usr/bin/env zsh
function switch_sink_applications()
{
echo switching applications
pacmd list-sink-inputs |
awk '/index:/{print $2}' |
xargs -r -I{} pacmd move-sink-input {} $1 ||
echo failed
}
current_default=$(pahelper.sh list | grep '*' | all_after_char ":" | xargs)
environment_variable_exists USE_ONLY_O_PASINK && pahelper.sh "$current_default"
# XXX: this does not prevent volumes higher than 100
pulsemixer "$@"
pashowvolume

View File

@ -1,3 +0,0 @@
#!/usr/bin/env bash
bash -c "$(rofi -input /dev/null -dmenu)"

View File

@ -1,4 +0,0 @@
#!/usr/bin/env zsh
split_current_chrome_tab.sh
xdotool key --clearmodifiers "Shift_L+Super_L+z"

View File

@ -1,3 +0,0 @@
#!/usr/bin/env zsh
chromix-too raw chrome.windows.getLastFocused '{"populate": true}' | jq -cM '.tabs[]' | jq 'select(.active)' | jq .id | xargs split_tab_by_id.sh

View File

@ -1,4 +0,0 @@
#!/usr/bin/env zsh
echo $1
chromix-too raw chrome.windows.create '{"tabId": '"$1}"

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
${IMALISON_CHROME_EX:-google-chrome-stable} $@

View File

@ -1,9 +0,0 @@
#!/usr/bin/env sh
HANGOUTS_PROFILE="Default"
[ -e $HOME/.hangouts_profile ] && HANGOUTS_PROFILE="$(cat $HOME/.hangouts_profile)"
start_chrome.sh \
--profile-directory="$HANGOUTS_PROFILE" \
--app-id=knipolnnllmklapflnccelgolnpehhpl

View File

@ -1,3 +0,0 @@
#!/usr/bin/env zsh
synergy_init_with_client imalison-home.local

View File

@ -1,3 +0,0 @@
#!/usr/bin/env sh
dbus-send --print-reply=literal --dest=taffybar.toggle /taffybar/toggle taffybar.toggle.toggleCurrent

View File

@ -1,3 +0,0 @@
#!/usr/bin/env zsh
xdotool type --clearmodifiers "$(keepass_system_password)"

View File

@ -1,3 +0,0 @@
#!/usr/bin/env zsh
wallpaper "$@"

View File

@ -1,34 +0,0 @@
#!/usr/bin/env sh
dpi="$1"
if [ -z $dpi ]; then
# Don't try to guess DPI. For a laptop, we don't want the same DPI as
# for an external screen. Just hardcode stuff...
case $(hostname),$(xrandr --current | \
sed -n 's/\([^ ]*\) connected .*[0-9][0-9]*x[0-9][0-9]*+[0-9][0-9]*+[0-9][0-9]* .*/\1/p' | \
sort | tr '\n' ':') in
imalison-arch,DVI-D-0:HDMI-0:) dpi=96 ;;
imalison-uber-loaner,eDP1:) dpi=96 ;;
imalison-mpb-arch,eDP-1:) dpi=144 ;;
imalison-mpb-arch,*:) dpi=144 ;;
*) dpi=96 ;;
esac
fi
echo "Setting dpi to $dpi"
# Build xsettingsd.local
cp ~/.xsettingsd ~/.xsettingsd.local
echo Xft/DPI $(( $dpi * 1024 )) >> ~/.xsettingsd.local
# # Also use xrdb for very old stuff (you know, LibreOffice)
echo Xft.dpi: "$dpi" | xrdb -merge
# Signal xsettingsd
pid=$(xprop -name xsettingsd _NET_WM_PID 2> /dev/null | awk '{print $NF}')
if [ x"$pid" = x ]; then
xsettingsd -c ~/.xsettingsd.local
else
kill -HUP $pid
fi

View File

@ -0,0 +1,9 @@
#!/usr/bin/env sh
function all_after_char {
while read -r line; do
echo ${line##*$1}
done;
}
all_after_char "$@"

View File

@ -0,0 +1,7 @@
#!/usr/bin/env sh
function command_exists {
hash "$1" 2>/dev/null 1>/dev/null
}
command_exists

View File

@ -0,0 +1,12 @@
#!/usr/bin/env sh
function dbus-introspect {
dbus-send --session \
--dest=$1 \
--type=method_call \
--print-reply \
$2 \
org.freedesktop.DBus.Introspectable.Introspect | tail -n +2 | sed -e "s/^ *string//"
}
dbus-introspect

View File

@ -0,0 +1,9 @@
#!/usr/bin/env sh
function environment_variable_exists {
eval "value=\"\${$1+x}\""
[ ! -z $value ]
}
environment_variable_exists

View File

@ -0,0 +1,8 @@
#!/usr/bin/env sh
function get_sink_input_by_pid {
get_sink_input_info.hs | jq 'select(.application_process_id == "'"$thePID"'")'
}
get_sink_input_by_pid

View File

@ -0,0 +1,7 @@
#!/usr/bin/env zsh
function list_interfaces {
ip link show | grep -vE '^ ' | get_cols -F ':' 2 | xargs -n 1
}
list_interfaces

View File

@ -0,0 +1,12 @@
#!/usr/bin/env sh
function load_default_map {
XKBDIR="$HOME/.xkb"
XKBMAPFILE="$XKBDIR/keymap/default"
echo "loading keymap from $XKBMAPFILE"
xkbcomp -I"$XKBDIR" "$XKBMAPFILE" "${DISPLAY%%.*}"
}
load_default_map

View File

@ -0,0 +1,24 @@
#!/usr/bin/env sh
function load_xkb_map {
XKBDIR="$HOME/.xkb"
XKBMAPFILE="$XKBDIR/keymap/$(hostname --fqdn)"
[[ -r "$XKBMAPFILE" ]] || XKBMAPFILE="${XKBMAPFILE%/*}/default"
echo "loading keymap from $XKBMAPFILE"
xkbcomp -I"$XKBDIR" "$XKBMAPFILE" "${DISPLAY%%.*}"
XKB_DEVICE_DIR="$XKBDIR/devices"
for file in "$XKB_DEVICE_DIR"/*
do
DEVICE_ID=$(xinput | grep "$(basename $file)" | head -n 1 | grep -Eo "id=[0-9]*" | grep -Eo "[0-9]*")
echo $file
echo device
echo "$DEVICE_ID"
# [ ! -z "$DEVICE_ID" ] && xkbcomp -I"$XKBDIR" -i "$DEVICE_ID" "$file" "${DISPLAY%%.*}"
done
}
load_xkb_map

14
dotfiles/lib/functions/localip Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env sh
function localip {
case `uname` in
'Darwin')
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'
;;
'Linux')
ip -4 addr | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v 127.0.0.1 | head -n 1
;;
esac
}
localip

View File

@ -52,7 +52,7 @@ function switch_sink_kmix_master()
function switch_sink()
{
switch_sink_default "$@"
xexswitch_sink_default "$@"
switch_sink_applications "$@"
switch_sink_kmix_master "$@"
}
@ -90,9 +90,13 @@ function help_me()
echo "Usage: $0 [gui|list|<sink name to switch to>]"
}
case "${1:-}" in
(""|list) list_sinks ;;
([0-9]*) switch_sink "$@" ;;
(gui) switch_gui ;;
(*) help_me ;;
esac
function pahelper {
case "${1:-}" in
(""|list) list_sinks ;;
([0-9]*) switch_sink "$@" ;;
(gui) switch_gui ;;
(*) help_me ;;
esac
}
pahelper

View File

@ -0,0 +1,7 @@
#!/usr/bin/env sh
function paismuted {
pactl list sinks | grep "$(pasink)" -A 10 | grep Mute | grep -q yes
}
paismuted

View File

@ -0,0 +1,7 @@
#!/usr/bin/env sh
function parse_timestamp {
date -d "@$1"
}
parse_timestamp

View File

@ -0,0 +1,15 @@
#!/usr/bin/env sh
function pashowvolume {
if paismuted; then
volnoti-show -m
else
actual=$(pavolume)
max=100
show=$(( actual < max ? actual : max ))
volnoti-show "$show"
fi
}
pashowvolume

7
dotfiles/lib/functions/pasink Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env sh
function pasink {
pacmd stat | awk -F": " '/^Default sink name: /{print $2}'
}
pasink "$@"

View File

@ -0,0 +1,10 @@
#!/usr/bin/env sh
function path_lines {
IFS=':' read -A ADDR <<< "$PATH"
for one_path in "${ADDR[@]}"; do
echo $one_path
done
}
path_lines

View File

@ -0,0 +1,9 @@
#!/usr/bin/env sh
function pavolume {
pacmd list-sinks |
awk '/^\s+name: /{indefault = $2 == "<'"$(pasink)"'>"}
/^\s+volume: / && indefault {print $5; exit}' | grep -Eo "[0-9]*"
}
pavolume

8
dotfiles/lib/functions/rlwhich Executable file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env sh
function rlwhich {
readlink -f "$(which $1)"
}
rlwhich "$@"

View File

@ -0,0 +1,7 @@
#!/usr/bin/env sh
function rofi_paswitch {
pahelper | tr -d '\n' | tr '>' '|' | rofi -i -dmenu -sep '|' | grep -Eo ' [0-9]*' | xargs pahelper
}
rofi_paswitch

View File

@ -0,0 +1,7 @@
#!/usr/bin/env sh
function run_if_exists {
command_exists "$0" && "$@"
}
run_if_exists

View File

@ -0,0 +1,8 @@
#!/usr/bin/env sh
function run_unity {
XDG_CURRENT_DESKTOP='Unity' "$@"
}
run_unity "$@"

View File

@ -0,0 +1,19 @@
#!/usr/bin/env sh
function switch_sink_applications()
{
echo switching applications
pacmd list-sink-inputs |
awk '/index:/{print $2}' |
xargs -r -I{} pacmd move-sink-input {} $1 ||
echo failed
}
function set_volume {
current_default=$(pahelper list | grep '*' | all_after_char ":" | xargs)
environment_variable_exists USE_ONLY_O_PASINK && pahelper "$current_default"
# XXX: this does not prevent volumes higher than 100
pulsemixer "$@"
pashowvolume
}

View File

@ -0,0 +1,11 @@
#!/usr/bin/env sh
function shell_contains () {
local e
for e in "${@:2}"; do
[[ "$1" == *"$e"* ]] && return 0
done
return 1
}
shell_contains

View File

@ -0,0 +1,7 @@
#!/usr/bin/env sh
function source_if_exists {
test -r "$1" && source "$1"
}
source_if_exists

View File

@ -0,0 +1,8 @@
#!/usr/bin/env sh
function timestamp {
date +%s
}
timestamp

View File

@ -0,0 +1,8 @@
#!/usr/bin/env sh
function toggle_taffybar {
dbus-send --print-reply=literal --dest=taffybar.toggle /taffybar/toggle taffybar.toggle.toggleCurrent
}
toggle_taffybar

View File

@ -1,298 +0,0 @@
function command_exists {
hash "$1" 2>/dev/null 1>/dev/null
}
function run_if_exists {
command_exists "$@" && "$@"
}
function shell_contains () {
local e
for e in "${@:2}"; do
[[ "$1" == *"$e"* ]] && return 0
done
return 1
}
function environment_variable_exists {
eval "value=\"\${$1+x}\""
[ ! -z $value ]
}
function get_python_scripts_path {
python -c "import sysconfig; print sysconfig.get_path('scripts')"
}
function path_lines {
IFS=':' read -A ADDR <<< "$PATH"
for one_path in "${ADDR[@]}"; do
echo $one_path
done
}
function indirect_expand {
eval "value=\"\${$1}\""
echo $value
}
function exists_in_path_var {
target=${2-PATH}
local path_contents="$(indirect_expand $target)"
[[ ":$path_contents:" == *":$1:"* ]]
}
function split_into_vars {
local string IFS
string="$1"
IFS="$2"
shift 2
read -r -- "$@" <<EOF
$string
EOF
}
function echo_split {
local IFS
IFS="$2" read -rA -- arr <<EOF
$1
EOF
for i in "${arr[@]}"; do
echo $i
done
}
function shell_contains {
local e
for e in "${@:2}"; do
[[ "$1" == *"$e"* ]] && return 0
done
return 1
}
function current_shell {
which "$(ps -p $$ | tail -1 | awk '{print $NF}' | sed 's/\-//')"
}
function is_zsh {
[ ! -z ${ZSH_VERSION+x} ]
}
function git_diff_add {
git status --porcelain | awk '{print $2}' | xargs -I filename sh -c "git du filename && git add filename"
}
function get_cols {
FS=' '
OPTIND=1
while getopts "F:" OPTCHAR; do
case $OPTCHAR in
F)
FS=$OPTARG
;;
esac
done
shift $((OPTIND-1))
gawk -f "$HOME/.lib/get_cols.awk" -v "cols=$*" -v "FS=$FS"
}
function filter_by_column_value {
awk '$'"$1"' == '"$2"' { print $0 }'
}
# Start an HTTP server from a directory, optionally specifying the port
function server {
local port="${1:-8000}"
sleep 1 && open "http://localhost:${port}/" &
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesnt break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
}
# All the dig info
function digga {
dig +nocmd "$1" any +multiline +noall +answer
}
function shell_stats() {
history 0 | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n20
}
function git_diff_replacing() {
local original_sha='HEAD~1'
local new_sha='HEAD'
OPTIND=1
while getopts "do:n:" OPTCHAR;
do
case $OPTCHAR in
o)
original_sha="$OPTARG"
;;
n)
new_sha="$OPTARG"
;;
d)
debug="true"
esac
done
shift $((OPTIND-1))
local replaced="$1"
local replacing="$2"
local replace_sha_string='$(echo filename | sed '"s:$replaced:$replacing:g"')'
test -z $debug || echo "Diffing from $original_sha to $new_sha, replacing $replaced with $replacing"
test -z $debug || git diff $original_sha $new_sha --name-only | grep -v "$replacing"
git diff $original_sha $new_sha --name-only | grep -v "$replacing" | xargs -I filename sh -c "git diff $original_sha:filename $new_sha:"$replace_sha_string
}
function git_reset_author() {
local should_update_command=''
local update_command=''
OPTIND=1
while getopts "a:e:A:E:h" OPTCHAR;
do
case $OPTCHAR in
a)
new_author="$OPTARG";
test -n "$update_command" && update_command="$update_command"' && '
update_command="$update_command"'export GIT_AUTHOR_NAME='"'$new_author'"' && export GIT_COMMITTER_NAME='"'$new_author'"
;;
A)
author_regex="$OPTARG";
test -n "$should_update_command" && should_update_command="$should_update_command"' && '
should_update_command=$should_update_command'[[ "$GIT_AUTHOR_NAME" =~ "'"$author_regex"'" ]]'
;;
e)
new_email="$OPTARG";
test -n "$update_command" && update_command="$update_command"' && '
update_command="$update_command"'export GIT_AUTHOR_EMAIL='"'$new_email'"' && export GIT_COMMITTER_EMAIL='"'$new_email'"
;;
E)
email_regex="$OPTARG";
test -n "$should_update_command" && should_update_command="$should_update_command"' && '
should_update_command=$should_update_command'[[ "$GIT_AUTHOR_EMAIL" =~ "'"$email_regex"'" ]]'
;;
h)
echo "Usage:
-a specify the new author/committer name.
-A specify a regex that will be used to filter commits by author name.
-e specify the new author/committer email.
-E specify a regex that will be used to filter commits by author email.
-h show this help message.
"
return
;;
esac
done
local filter_branch_command="$should_update_command"' && '"$update_command"' || test true'
git filter-branch -f --env-filter $filter_branch_command -- --all
}
alias git_reset_author_to_user='git_reset_author -a "$(git config --get user.name)" -e "$(git config --get user.email)" '
alias git_reset_author_from_user='git_reset_author -A "$(git config --get user.name)" -E "$(git config --get user.email)" '
function git_prune_all_history_involving {
git filter-branch --force --index-filter \
"git rm -r --cached --ignore-unmatch $1" \
--prune-empty --tag-name-filter cat -- --all
}
function pip_package_location() {
pip show $1 | grep Location | get_cols 2
}
function git_config_string() {
git config -f $1 --list | xargs -I kv printf '-c \"%s\" ' kv
}
function track_modified {
local timestamp_file="/tmp/__track_modified_timestamp__"
touch $timestamp_file
stat $timestamp_file
echo "Press any key to execute find command"
read -r key
echo "Finding..."
find $1 -cnewer "$timestamp_file"
}
function python_module_path {
python -c "import os, $1; print(os.path.dirname($1.__file__))"
}
function timestamp {
date +%s
}
function parse_timestamp {
date -d "@$1"
}
function parse_timestamp2 {
date -d "@$(echo $1 | cut -c -10)" -Iseconds
}
function file_ends_with_newline {
[[ $(tail -c1 "$1" | wc -l) -gt 0 ]]
}
function source_if_exists {
test -r "$1" && source "$1"
}
function edit_script {
$EDITOR "$(which $1)"
}
function which_readlink {
readlink -f "$(which $1)"
}
function localip {
case `uname` in
'Darwin')
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'
;;
'Linux')
ip -4 addr | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | grep -v 127.0.0.1 | head -n 1
;;
esac
}
function all_lines_after {
sed -n "/$1/"'$p'
}
function list_interfaces {
ip link show | grep -vE '^ ' | get_cols -F ':' 2 | xargs -n 1
}
function all_after_char {
while read -r line; do
echo ${line##*$1}
done;
}
function pasink {
pacmd stat | awk -F": " '/^Default sink name: /{print $2}'
}
function pavolume {
pacmd list-sinks |
awk '/^\s+name: /{indefault = $2 == "<'"$(pasink)"'>"}
/^\s+volume: / && indefault {print $5; exit}' | grep -Eo "[0-9]*"
}
function paismuted {
pactl list sinks | grep "$(pasink)" -A 10 | grep Mute | grep -q yes
}
function pashowvolume {
if paismuted; then
volnoti-show -m
else
volnoti-show "$(min $(pavolume) 100)"
fi
}
function pashowinputbypid {
get_sink_input_info.hs | jq 'select(.application_process_id == "'"$1"'")'
}

View File

@ -1,7 +1,7 @@
# This is necessary for tramp.
[[ $TERM == "dumb" ]] && unsetopt zle && PS1='$ ' && return
test -r ~/.custom.sh && source ~/.custom.sh
source_if_exists ~/.custom.sh
source_if_exists ~/.this-machine.sh
function emacs_ansi_term_support {

View File

@ -4,6 +4,7 @@
./users.nix
./fonts.nix
./essential.nix
./environment.nix
];
# Allow all the things
@ -67,19 +68,6 @@
# TODO: Add a comment explaining what this does.
services.gnome.at-spi2-core.enable = true;
# Shell configuration
programs.zsh = {
enable = true;
syntaxHighlighting = {
enable = true;
};
ohMyZsh = {
enable = true;
plugins = [ "git" "sudo" "pip" ];
};
spaceship-prompt.enable = true;
};
services.openssh.enable = true;
services.autorandr.enable = true;
@ -90,14 +78,6 @@
hardware.keyboard.zsa.enable = true;
environment = {
homeBinInPath = true;
localBinInPath = true;
extraInit = ''
export PATH="$HOME/.lib/bin:$PATH"
'';
};
services.xserver = {
exportConfiguration = true;
enable = true;

View File

@ -134,7 +134,7 @@
},
"git-ignore-nix_4": {
"inputs": {
"nixpkgs": "nixpkgs_6"
"nixpkgs": "nixpkgs_7"
},
"locked": {
"lastModified": 1626413882,
@ -153,7 +153,7 @@
},
"git-ignore-nix_5": {
"inputs": {
"nixpkgs": "nixpkgs_8"
"nixpkgs": "nixpkgs_9"
},
"locked": {
"lastModified": 1626413882,
@ -188,37 +188,19 @@
"type": "github"
}
},
"gitIgnoreNix_2": {
"inputs": {
"nixpkgs": "nixpkgs_11"
},
"locked": {
"lastModified": 1626413882,
"narHash": "sha256-ZHw1YVsrs7rG9jPEH0ZabbbCTdnVr48FAwK6GCQPSF4=",
"owner": "IvanMalison",
"repo": "gitignore.nix",
"rev": "a2ffb0bfd0145ca57d792a6f9f76f5c305ca29b7",
"type": "github"
},
"original": {
"owner": "IvanMalison",
"repo": "gitignore.nix",
"type": "github"
}
},
"gtk-sni-tray": {
"inputs": {
"flake-utils": "flake-utils_4",
"git-ignore-nix": "git-ignore-nix_4",
"nixpkgs": "nixpkgs_7",
"flake-utils": "flake-utils_3",
"git-ignore-nix": "git-ignore-nix_3",
"nixpkgs": "nixpkgs_6",
"status-notifier-item": "status-notifier-item"
},
"locked": {
"lastModified": 1627097793,
"narHash": "sha256-/VADe26PqxUCUav3gVtDp0ov8irDyYMWINFBDGmP2Ik=",
"lastModified": 1627764331,
"narHash": "sha256-AgJGmLGNSraNr/zL+IIYF/qFUY0fEfivxfIoqIsiRWk=",
"owner": "taffybar",
"repo": "gtk-sni-tray",
"rev": "07a8b24db5245b58ca39ed6c2fd6bac4e51ccc13",
"rev": "ceb15d9c0980d4359ad1b0374ba221229a14acb7",
"type": "github"
},
"original": {
@ -235,7 +217,7 @@
]
},
"locked": {
"narHash": "sha256-Yz2tpRVaNPxKiBkw8lEzH77/MuI4zVOiCk4LE61pOII=",
"narHash": "sha256-FNXyt5dlC8JG/0Tsf8nrJ+DDP5uip9Tsqt3WllmAkk8=",
"path": "./home-manager",
"type": "path"
},
@ -300,7 +282,7 @@
},
"nixpkgs": {
"locked": {
"narHash": "sha256-XaIGzF86aDiWYO4pHH3v4KsCmr3kSzIQV2+OX3kUH8M=",
"narHash": "sha256-Iv7J5n9zN4ejsQjnAJLDv+/+/+BH/kgfPAzMXrcqsZ0=",
"path": "./nixpkgs",
"type": "path"
},
@ -311,19 +293,8 @@
},
"nixpkgs_10": {
"locked": {
"narHash": "sha256-nUOrWoAiH6e3u0+k8FxaqdeVz9JnO3KSLfCo3j+hHFQ=",
"path": "/nix/store/4jd0wffvcy4ljdlxasf201pm57s6cq57-source",
"type": "path"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_11": {
"locked": {
"narHash": "sha256-nUOrWoAiH6e3u0+k8FxaqdeVz9JnO3KSLfCo3j+hHFQ=",
"path": "/nix/store/4jd0wffvcy4ljdlxasf201pm57s6cq57-source",
"narHash": "sha256-Iv7J5n9zN4ejsQjnAJLDv+/+/+BH/kgfPAzMXrcqsZ0=",
"path": "./nixpkgs",
"type": "path"
},
"original": {
@ -333,8 +304,8 @@
},
"nixpkgs_2": {
"locked": {
"narHash": "sha256-nUOrWoAiH6e3u0+k8FxaqdeVz9JnO3KSLfCo3j+hHFQ=",
"path": "/nix/store/4jd0wffvcy4ljdlxasf201pm57s6cq57-source",
"narHash": "sha256-Iv7J5n9zN4ejsQjnAJLDv+/+/+BH/kgfPAzMXrcqsZ0=",
"path": "./nixpkgs",
"type": "path"
},
"original": {
@ -344,8 +315,8 @@
},
"nixpkgs_3": {
"locked": {
"narHash": "sha256-nUOrWoAiH6e3u0+k8FxaqdeVz9JnO3KSLfCo3j+hHFQ=",
"path": "/nix/store/4jd0wffvcy4ljdlxasf201pm57s6cq57-source",
"narHash": "sha256-Iv7J5n9zN4ejsQjnAJLDv+/+/+BH/kgfPAzMXrcqsZ0=",
"path": "./nixpkgs",
"type": "path"
},
"original": {
@ -355,8 +326,8 @@
},
"nixpkgs_4": {
"locked": {
"narHash": "sha256-nUOrWoAiH6e3u0+k8FxaqdeVz9JnO3KSLfCo3j+hHFQ=",
"path": "/nix/store/4jd0wffvcy4ljdlxasf201pm57s6cq57-source",
"narHash": "sha256-Iv7J5n9zN4ejsQjnAJLDv+/+/+BH/kgfPAzMXrcqsZ0=",
"path": "./nixpkgs",
"type": "path"
},
"original": {
@ -366,8 +337,8 @@
},
"nixpkgs_5": {
"locked": {
"narHash": "sha256-nUOrWoAiH6e3u0+k8FxaqdeVz9JnO3KSLfCo3j+hHFQ=",
"path": "/nix/store/4jd0wffvcy4ljdlxasf201pm57s6cq57-source",
"narHash": "sha256-Iv7J5n9zN4ejsQjnAJLDv+/+/+BH/kgfPAzMXrcqsZ0=",
"path": "./nixpkgs",
"type": "path"
},
"original": {
@ -377,8 +348,8 @@
},
"nixpkgs_6": {
"locked": {
"narHash": "sha256-nUOrWoAiH6e3u0+k8FxaqdeVz9JnO3KSLfCo3j+hHFQ=",
"path": "/nix/store/4jd0wffvcy4ljdlxasf201pm57s6cq57-source",
"narHash": "sha256-Iv7J5n9zN4ejsQjnAJLDv+/+/+BH/kgfPAzMXrcqsZ0=",
"path": "./nixpkgs",
"type": "path"
},
"original": {
@ -388,8 +359,8 @@
},
"nixpkgs_7": {
"locked": {
"narHash": "sha256-nUOrWoAiH6e3u0+k8FxaqdeVz9JnO3KSLfCo3j+hHFQ=",
"path": "/nix/store/4jd0wffvcy4ljdlxasf201pm57s6cq57-source",
"narHash": "sha256-Iv7J5n9zN4ejsQjnAJLDv+/+/+BH/kgfPAzMXrcqsZ0=",
"path": "./nixpkgs",
"type": "path"
},
"original": {
@ -399,8 +370,8 @@
},
"nixpkgs_8": {
"locked": {
"narHash": "sha256-nUOrWoAiH6e3u0+k8FxaqdeVz9JnO3KSLfCo3j+hHFQ=",
"path": "/nix/store/4jd0wffvcy4ljdlxasf201pm57s6cq57-source",
"narHash": "sha256-Iv7J5n9zN4ejsQjnAJLDv+/+/+BH/kgfPAzMXrcqsZ0=",
"path": "./nixpkgs",
"type": "path"
},
"original": {
@ -410,8 +381,8 @@
},
"nixpkgs_9": {
"locked": {
"narHash": "sha256-nUOrWoAiH6e3u0+k8FxaqdeVz9JnO3KSLfCo3j+hHFQ=",
"path": "/nix/store/4jd0wffvcy4ljdlxasf201pm57s6cq57-source",
"narHash": "sha256-Iv7J5n9zN4ejsQjnAJLDv+/+/+BH/kgfPAzMXrcqsZ0=",
"path": "./nixpkgs",
"type": "path"
},
"original": {
@ -426,11 +397,11 @@
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1626744467,
"narHash": "sha256-YkJkOZTz1yxj63e6kAOkgxPmK0CIFpDNXyMHvxctn9k=",
"lastModified": 1627789093,
"narHash": "sha256-rnQ7vDF9g2xqRpw62lkCyxBiq6cXhWgfoF7lx1WoNMI=",
"owner": "IvanMalison",
"repo": "notifications-tray-icon",
"rev": "0d83e7fba0592bec4566662140ab197491d99126",
"rev": "2fd47641d0cb046c78de9b4577cb30bc49e607ea",
"type": "github"
},
"original": {
@ -454,16 +425,16 @@
},
"status-notifier-item": {
"inputs": {
"flake-utils": "flake-utils_5",
"git-ignore-nix": "git-ignore-nix_5",
"nixpkgs": "nixpkgs_9"
"flake-utils": "flake-utils_4",
"git-ignore-nix": "git-ignore-nix_4",
"nixpkgs": "nixpkgs_8"
},
"locked": {
"lastModified": 1627094793,
"narHash": "sha256-teycP5kmokSCxtJjRaYEGx8DWnGKKO6qQG37iqdIdEM=",
"lastModified": 1627765570,
"narHash": "sha256-EJHvVtYQvohhOhznY5Iy3GR0zyjwMF+lsCr5hgL3ziw=",
"owner": "taffybar",
"repo": "status-notifier-item",
"rev": "90f34bc859edbdb8c63802ee8a149d1fefac4415",
"rev": "c5d7d898e4f13ec9864e5047b6da25de62535672",
"type": "github"
},
"original": {
@ -477,49 +448,31 @@
"inputs": {
"flake-utils": "flake-utils_2",
"git-ignore-nix": "git-ignore-nix_2",
"nixpkgs": [
"nixpkgs"
],
"taffybar": "taffybar_2"
},
"locked": {
"narHash": "sha256-gHDOm6LziKcuXsmFnVD58cE3VBo0zBEZ+3mw++bJwZs=",
"path": "../dotfiles/config/taffybar",
"type": "path"
},
"original": {
"path": "../dotfiles/config/taffybar",
"type": "path"
}
},
"taffybar_2": {
"inputs": {
"flake-utils": "flake-utils_3",
"git-ignore-nix": "git-ignore-nix_3",
"gtk-sni-tray": "gtk-sni-tray",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"narHash": "sha256-8/Jliml56I/GahY4fG6F+nEwJubtCjJgbd06dk78pQU=",
"path": "./taffybar",
"narHash": "sha256-mN5ZDg16JysS4+JYBgfr8klx34lND5c6qLS/DOYMWZA=",
"path": "../dotfiles/config/taffybar/taffybar",
"type": "path"
},
"original": {
"path": "./taffybar",
"path": "../dotfiles/config/taffybar/taffybar",
"type": "path"
}
},
"xmonad": {
"inputs": {
"gitIgnoreNix": "gitIgnoreNix",
"flake-utils": "flake-utils_5",
"git-ignore-nix": "git-ignore-nix_5",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"narHash": "sha256-tRk4foS5QiPx/GwTSl6+lfY15d1Y3822DjDxqMHjf34=",
"narHash": "sha256-LsqmlW82Zmyj4PW8T3kJTm+p599/lG1fOcEa1Sgcjg4=",
"path": "../dotfiles/config/xmonad/xmonad",
"type": "path"
},
@ -530,13 +483,13 @@
},
"xmonad-contrib": {
"inputs": {
"gitIgnoreNix": "gitIgnoreNix_2",
"gitIgnoreNix": "gitIgnoreNix",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"narHash": "sha256-jbikN00AydMA542fcPuVgMcVobagwf6/Wbgj804PjYA=",
"narHash": "sha256-RsCxI72sx+LIQTz8uAj+8qvgmPhENOhFDDyZjHbPohU=",
"path": "../dotfiles/config/xmonad/xmonad-contrib",
"type": "path"
},