1
0
Fork 0

Add new bin scripts

This commit is contained in:
Gregory Eremin 2020-09-12 09:59:24 +02:00
parent 9b3ff362cf
commit 5f10a0fc70
13 changed files with 204 additions and 37 deletions

View File

@ -1,8 +1,8 @@
## .dotfiles ## Gregory's dotfiles
Installation: ### Installation
```bash ```bash
git clone git@github.com:magnolia-fan/dotfiles.git ~/.dotfiles git clone git@github.com:localhots/dotfiles.git ~/dotfiles
~/.dotfiles/setup.bash ~/dotfiles/setup.bash
``` ```

View File

@ -1,33 +0,0 @@
#!/usr/bin/env ruby
# Usage: gitio URL [CODE]
#
# Turns a github.com URL
# into a git.io URL
#
# Created by @defunkt:
# https://gist.github.com/1209316
#
# Copies the git.io URL to your clipboard.
url = ARGV[0]
code = ARGV[1]
if url !~ /^(https?:\/\/)?(gist\.)?github.com/
abort "* github.com URLs only"
end
if url !~ /^http/
url = "https://#{url}"
end
if code
code = "-F code=#{code}"
end
output = `curl -i http://git.io -F 'url=#{url}' #{code} 2> /dev/null`
if output =~ /Location: (.+)\n?/
puts $1
`echo #$1 | pbcopy`
else
puts output
end

16
bin/mymenu Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
CHOICE=`wofi -i -d -W 400 -H 250 -p 'Choose' << EOF
Services
VPN
EOF`
case $CHOICE in
'Services')
mymenu-services
;;
'VPN')
mymenu-vpn
;;
esac

28
bin/mymenu-services Executable file
View File

@ -0,0 +1,28 @@
#!/bin/bash
service_dir="$HOME/.config/systemd/user"
choice=$(grep "Description=" $service_dir/*.service | cut -d'=' -f2 | wofi -i -d -W 600 -H 300 -p Service)
[[ -z "$choice" ]] && exit
service=$(grep "$choice" $service_dir/*.service | cut -d':' -f1 | rev | cut -d'/' -f1 | rev)
cnt=$(systemctl --user status $service | grep -c "active (running)")
service_status=$([[ "$cnt" -eq "0" ]] && echo "Inactive" || echo "Active")
if [ "$service_status" = "Active" ]; then
choices="Restart\nStop"
else
choices="Start"
fi
choice=$(echo -e $choices | wofi -i -d -W 400 -H 250 -p "Status: $service_status")
case $choice in
'Start')
systemctl --user start $service
;;
'Restart')
systemctl --user restart $service
;;
'Stop')
systemctl --user stop $service
esac

17
bin/mymenu-vpn Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
if [ "$(nmcli -g GENERAL.STATE con show $VPN_NAME || true)" == "activated" ]; then
choices=Disconnect
else
choices=Connect
fi
choice=$(echo -e $choices | wofi -i -d -W 400 -H 250 -p $VPN_NAME)
case $choice in
'Connect')
nmcli con up $VPN_NAME
;;
'Disconnect')
nmcli con down $VPN_NAME
esac

3
bin/screens-lock Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
swaylock --scaling fill -i $HOME/Pictures/Wallpapers/dots-dark-4k-vi-2560x1440.jpg

3
bin/screens-off Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
swaymsg "output * dpms off"

3
bin/screens-on Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
swaymsg "output * dpms on"

33
bin/screenshot-wofi-text-align Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env ruby
# This script is used by dotfiles/bin/sway-interactive-screenshot to align window
# coordinates, sizes and names in columns.
#
# Turns this:
# 2560,60 760x1020 wl-clipsync
# 3320,60 1160x1020 go-api
# 768,60 1792x1380 Trending repositories on GitHub today - Mozilla Firefox
# 0,60 768x675 screenshot-wofi-text-align (~/dotfiles/bin) - VIM
# 0,765 768x675 Pictures
#
# Into this:
# 2560,60 760x1020 wl-clipsync
# 3320,60 1160x1020 go-api
# 768,60 1792x1380 Trending repositories on GitHub today - Mozilla Firefox
# 0,60 768x675 screenshot-wofi-text-align (~/dotfiles/bin) - VIM
# 0,765 768x675 Pictures
max_pos_len = 0
max_dim_len = 0
items = STDIN.read.split("\n").map do |row|
row.match(/(\d+,\d+)\s(\d+x\d+)\t(.*)/) do |m|
max_pos_len = m[1].length if m[1].length > max_pos_len
max_dim_len = m[2].length if m[2].length > max_dim_len
{pos: m[1], dim: m[2], name: m[3]}
end
end
items.each do |item|
puts "#{item[:pos].ljust(max_pos_len)} "+
"#{item[:dim].ljust(max_dim_len)} \t#{item[:name]}"
end

68
bin/sway-interactive-screenshot Executable file
View File

@ -0,0 +1,68 @@
#!/bin/bash
# This is a modified version of sway-interactive-screenshot made by moverest
# https://github.com/moverest/sway-interactive-screenshot/
# `list_geometry` returns the geometry of the focused of visible windows. You can also get they title
# by setting a second argument to `with_description`. The geometry and the title are seperated by `\t`.
#
# Arguments:
# $1: `focused` or `visible`
# $2: `with_description` or nothing
#
# Output examples:
# - with the `with_description` option:
# 12,43 100x200\tTermite
# - without the `with_description` option:
# 12,43 100x200
function list_geometry () {
[ "$2" = with_description ] && local append="\t\(.name)" || local append=
swaymsg -t get_tree | jq -r '.. | (.nodes? // empty)[] | select(.'$1' and .pid) | "\(.rect.x),\(.rect.y) \(.rect.width)x\(.rect.height)'$append'"'
}
# WINDOWS=`list_geometry visible with_description`
WINDOWS=`list_geometry visible with_description | screenshot-wofi-text-align`
FOCUSED=`list_geometry focused`
# CHOICE=`rofi -dmenu -i -p 'Screenshot' << EOF
CHOICE=`wofi -i -d -W 800 -p 'Screenshot' << EOF
Focused Window
Focused Screen
All Screens
Region
$WINDOWS
EOF`
SAVEDIR="$(xdg-user-dir PICTURES)/Screenshots"
mkdir -p "$SAVEDIR"
FILENAME="$SAVEDIR/$(date +'Screenshot %Y-%m-%d %H:%M:%S.png')"
EXPANDED_FILENAME="${FILENAME/#\~/$HOME}"
case $CHOICE in
'All Screens')
grim "$EXPANDED_FILENAME"
;;
'Focused Screen')
grim -o "$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')" "$EXPANDED_FILENAME"
;;
Region)
grim -g "$(slurp)" "$EXPANDED_FILENAME"
;;
'Focused Window')
grim -g "$FOCUSED" "$EXPANDED_FILENAME"
;;
'')
# notify-send "Screenshot" "Cancelled"
exit 0
;;
*)
GEOMETRY="`echo \"$CHOICE\" | cut -d$'\t' -f1`"
grim -g "$GEOMETRY" "$EXPANDED_FILENAME"
esac
wl-copy < $(echo "$EXPANDED_FILENAME")
notify-send "Screenshot" "File saved as <i>'$FILENAME'</i> and copied to the clipboard." -i "$EXPANDED_FILENAME"

8
bin/vpn-status Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
# export VPN_NAME=MyVPN from dotfiles/secrets/vpn
if [ "$(nmcli -g GENERAL.STATE con show $VPN_NAME)" == "activated" ]; then
echo ""
else
echo ""
fi

12
bin/vpn-toggle Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
# export VPN_NAME=MyVPN from dotfiles/secrets/vpn
if [ "$(nmcli -g GENERAL.STATE con show $VPN_NAME)" == "activated" ]; then
echo Disconnecting
nmcli con down "$VPN_NAME"
else
echo Connecting
nmcli con up "$VPN_NAME"
fi
exit 0

9
bin/waybar-pacman Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
# Used by waybar
# Returns a message when there is more than 50 packages available for update
nupdates=$(checkupdates | wc -l)
if [ $nupdates -gt 50 ]; then
echo "  $nupdates "
fi