New functions/bin structure
This commit is contained in:
@@ -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//"
|
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
get_sink_input_info.hs | jq 'select(.application_process_id == "'"$thePID"'")'
|
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
ip link show | grep -vE '^ ' | get_cols -F ':' 2 | xargs -n 1
|
@@ -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
|
@@ -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
|
||||
|
@@ -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 - "$@"
|
@@ -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
|
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
find ~/Pictures/wallpaper/use -type f -or -type l | rofi -i -dmenu | xargs wallpaper.sh
|
@@ -1,6 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cd "$( dirname "${BASH_SOURCE[0]}" )"
|
||||
echo "$@"
|
||||
stack build
|
||||
stack runghc "$@"
|
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
XDG_CURRENT_DESKTOP='Unity' "$@"
|
@@ -1,5 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
args="$(rofi -input /dev/null -dmenu)"
|
||||
sleep 1
|
||||
scrot $args
|
@@ -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
|
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
bash -c "$(rofi -input /dev/null -dmenu)"
|
@@ -1,4 +0,0 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
split_current_chrome_tab.sh
|
||||
xdotool key --clearmodifiers "Shift_L+Super_L+z"
|
@@ -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
|
@@ -1,4 +0,0 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
echo $1
|
||||
chromix-too raw chrome.windows.create '{"tabId": '"$1}"
|
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
${IMALISON_CHROME_EX:-google-chrome-stable} $@
|
@@ -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
|
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
synergy_init_with_client imalison-home.local
|
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
dbus-send --print-reply=literal --dest=taffybar.toggle /taffybar/toggle taffybar.toggle.toggleCurrent
|
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
xdotool type --clearmodifiers "$(keepass_system_password)"
|
@@ -1,3 +0,0 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
wallpaper "$@"
|
@@ -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
|
9
dotfiles/lib/functions/all_after_char
Executable file
9
dotfiles/lib/functions/all_after_char
Executable 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 "$@"
|
7
dotfiles/lib/functions/command_exists
Executable file
7
dotfiles/lib/functions/command_exists
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
function command_exists {
|
||||
hash "$1" 2>/dev/null 1>/dev/null
|
||||
}
|
||||
|
||||
command_exists
|
12
dotfiles/lib/functions/dbus_introspect
Executable file
12
dotfiles/lib/functions/dbus_introspect
Executable 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
|
9
dotfiles/lib/functions/environment_variable_exists
Executable file
9
dotfiles/lib/functions/environment_variable_exists
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
function environment_variable_exists {
|
||||
eval "value=\"\${$1+x}\""
|
||||
[ ! -z $value ]
|
||||
}
|
||||
|
||||
environment_variable_exists
|
||||
|
8
dotfiles/lib/functions/get_sink_input_by_pid
Executable file
8
dotfiles/lib/functions/get_sink_input_by_pid
Executable 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
|
||||
|
7
dotfiles/lib/functions/list_interfaces
Executable file
7
dotfiles/lib/functions/list_interfaces
Executable 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
|
12
dotfiles/lib/functions/load_default_map
Executable file
12
dotfiles/lib/functions/load_default_map
Executable 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
|
24
dotfiles/lib/functions/load_xkb_map
Executable file
24
dotfiles/lib/functions/load_xkb_map
Executable 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
14
dotfiles/lib/functions/localip
Executable 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
|
@@ -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
|
7
dotfiles/lib/functions/paismuted
Executable file
7
dotfiles/lib/functions/paismuted
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
function paismuted {
|
||||
pactl list sinks | grep "$(pasink)" -A 10 | grep Mute | grep -q yes
|
||||
}
|
||||
|
||||
paismuted
|
7
dotfiles/lib/functions/parse_timestamp
Executable file
7
dotfiles/lib/functions/parse_timestamp
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
function parse_timestamp {
|
||||
date -d "@$1"
|
||||
}
|
||||
|
||||
parse_timestamp
|
15
dotfiles/lib/functions/pashowvolume
Executable file
15
dotfiles/lib/functions/pashowvolume
Executable 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
7
dotfiles/lib/functions/pasink
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
function pasink {
|
||||
pacmd stat | awk -F": " '/^Default sink name: /{print $2}'
|
||||
}
|
||||
|
||||
pasink "$@"
|
10
dotfiles/lib/functions/path_lines
Executable file
10
dotfiles/lib/functions/path_lines
Executable 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
|
9
dotfiles/lib/functions/pavolume
Executable file
9
dotfiles/lib/functions/pavolume
Executable 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
8
dotfiles/lib/functions/rlwhich
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
function rlwhich {
|
||||
readlink -f "$(which $1)"
|
||||
}
|
||||
|
||||
rlwhich "$@"
|
||||
|
7
dotfiles/lib/functions/rofi_paswitch
Executable file
7
dotfiles/lib/functions/rofi_paswitch
Executable 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
|
7
dotfiles/lib/functions/run_if_exists
Executable file
7
dotfiles/lib/functions/run_if_exists
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
function run_if_exists {
|
||||
command_exists "$0" && "$@"
|
||||
}
|
||||
|
||||
run_if_exists
|
8
dotfiles/lib/functions/run_unity
Executable file
8
dotfiles/lib/functions/run_unity
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
function run_unity {
|
||||
XDG_CURRENT_DESKTOP='Unity' "$@"
|
||||
}
|
||||
|
||||
run_unity "$@"
|
||||
|
19
dotfiles/lib/functions/set_volume
Executable file
19
dotfiles/lib/functions/set_volume
Executable 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
|
||||
}
|
11
dotfiles/lib/functions/shell_contains
Executable file
11
dotfiles/lib/functions/shell_contains
Executable 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
|
7
dotfiles/lib/functions/source_if_exists
Executable file
7
dotfiles/lib/functions/source_if_exists
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
function source_if_exists {
|
||||
test -r "$1" && source "$1"
|
||||
}
|
||||
|
||||
source_if_exists
|
8
dotfiles/lib/functions/timestamp
Executable file
8
dotfiles/lib/functions/timestamp
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
function timestamp {
|
||||
date +%s
|
||||
}
|
||||
|
||||
timestamp
|
||||
|
8
dotfiles/lib/functions/toggle_taffybar
Executable file
8
dotfiles/lib/functions/toggle_taffybar
Executable 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
|
||||
|
@@ -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 doesn’t 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"'")'
|
||||
}
|
Reference in New Issue
Block a user