From 5f10a0fc70edec60dbd1b43271e737f9d25cb4fd Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Sat, 12 Sep 2020 09:59:24 +0200 Subject: [PATCH] Add new bin scripts --- README.md | 8 ++-- bin/gitio | 33 ---------------- bin/mymenu | 16 ++++++++ bin/mymenu-services | 28 ++++++++++++++ bin/mymenu-vpn | 17 +++++++++ bin/screens-lock | 3 ++ bin/screens-off | 3 ++ bin/screens-on | 3 ++ bin/screenshot-wofi-text-align | 33 ++++++++++++++++ bin/sway-interactive-screenshot | 68 +++++++++++++++++++++++++++++++++ bin/vpn-status | 8 ++++ bin/vpn-toggle | 12 ++++++ bin/waybar-pacman | 9 +++++ 13 files changed, 204 insertions(+), 37 deletions(-) delete mode 100755 bin/gitio create mode 100755 bin/mymenu create mode 100755 bin/mymenu-services create mode 100755 bin/mymenu-vpn create mode 100755 bin/screens-lock create mode 100755 bin/screens-off create mode 100755 bin/screens-on create mode 100755 bin/screenshot-wofi-text-align create mode 100755 bin/sway-interactive-screenshot create mode 100755 bin/vpn-status create mode 100755 bin/vpn-toggle create mode 100755 bin/waybar-pacman diff --git a/README.md b/README.md index fe6743e..320652a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -## .dotfiles +## Gregory's dotfiles -Installation: +### Installation ```bash -git clone git@github.com:magnolia-fan/dotfiles.git ~/.dotfiles -~/.dotfiles/setup.bash +git clone git@github.com:localhots/dotfiles.git ~/dotfiles +~/dotfiles/setup.bash ``` diff --git a/bin/gitio b/bin/gitio deleted file mode 100755 index 30bae81..0000000 --- a/bin/gitio +++ /dev/null @@ -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 diff --git a/bin/mymenu b/bin/mymenu new file mode 100755 index 0000000..59fec74 --- /dev/null +++ b/bin/mymenu @@ -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 + diff --git a/bin/mymenu-services b/bin/mymenu-services new file mode 100755 index 0000000..f282e3e --- /dev/null +++ b/bin/mymenu-services @@ -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 + diff --git a/bin/mymenu-vpn b/bin/mymenu-vpn new file mode 100755 index 0000000..ecbaf0b --- /dev/null +++ b/bin/mymenu-vpn @@ -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 + diff --git a/bin/screens-lock b/bin/screens-lock new file mode 100755 index 0000000..dd248aa --- /dev/null +++ b/bin/screens-lock @@ -0,0 +1,3 @@ +#!/bin/bash + +swaylock --scaling fill -i $HOME/Pictures/Wallpapers/dots-dark-4k-vi-2560x1440.jpg diff --git a/bin/screens-off b/bin/screens-off new file mode 100755 index 0000000..7d9797c --- /dev/null +++ b/bin/screens-off @@ -0,0 +1,3 @@ +#!/bin/bash + +swaymsg "output * dpms off" diff --git a/bin/screens-on b/bin/screens-on new file mode 100755 index 0000000..558baeb --- /dev/null +++ b/bin/screens-on @@ -0,0 +1,3 @@ +#!/bin/bash + +swaymsg "output * dpms on" diff --git a/bin/screenshot-wofi-text-align b/bin/screenshot-wofi-text-align new file mode 100755 index 0000000..c9fab1a --- /dev/null +++ b/bin/screenshot-wofi-text-align @@ -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 diff --git a/bin/sway-interactive-screenshot b/bin/sway-interactive-screenshot new file mode 100755 index 0000000..37d1994 --- /dev/null +++ b/bin/sway-interactive-screenshot @@ -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 '$FILENAME' and copied to the clipboard." -i "$EXPANDED_FILENAME" diff --git a/bin/vpn-status b/bin/vpn-status new file mode 100755 index 0000000..741b715 --- /dev/null +++ b/bin/vpn-status @@ -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 diff --git a/bin/vpn-toggle b/bin/vpn-toggle new file mode 100755 index 0000000..117118e --- /dev/null +++ b/bin/vpn-toggle @@ -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 diff --git a/bin/waybar-pacman b/bin/waybar-pacman new file mode 100755 index 0000000..e6c1527 --- /dev/null +++ b/bin/waybar-pacman @@ -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