From 7d9c45878f9be55943b5eea3bf5f94c49c237d66 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Tue, 16 Feb 2021 01:07:53 +0100 Subject: [PATCH] Add some scripts --- scripts/ex | 22 ++++++++++++++++++++++ scripts/mdToPdf | 10 ++++++++++ scripts/rofi/config-selector.py | 20 ++++++++++++++++++++ scripts/tmux/fcitx | 28 ++++++++++++++++++++++++++++ scripts/tmux/mpd | 18 ++++++++++++++++++ scripts/toCbz | 6 ++++++ scripts/touchpadToggle.sh | 16 ++++++++++++++++ 7 files changed, 120 insertions(+) create mode 100644 scripts/ex create mode 100755 scripts/mdToPdf create mode 100755 scripts/rofi/config-selector.py create mode 100755 scripts/tmux/fcitx create mode 100755 scripts/tmux/mpd create mode 100755 scripts/toCbz create mode 100755 scripts/touchpadToggle.sh diff --git a/scripts/ex b/scripts/ex new file mode 100644 index 0000000..a7105c0 --- /dev/null +++ b/scripts/ex @@ -0,0 +1,22 @@ +#!/bin/bash + +# ex - archive extractor +# usage: ex +if [ -f $1 ] ; then + case $1 in + *.tar.bz2) tar xjf $1 ;; + *.tar.gz) tar xzf $1 ;; + *.bz2) bunzip2 $1 ;; + *.rar) unrar x $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar xf $1 ;; + *.tbz2) tar xjf $1 ;; + *.tgz) tar xzf $1 ;; + *.zip) unzip $1 ;; + *.Z) uncompress $1;; + *.7z) 7z x $1 ;; + *) echo "'$1' cannot be extracted via ex()" ;; + esac +else + echo "'$1' is not a valid file" +fi diff --git a/scripts/mdToPdf b/scripts/mdToPdf new file mode 100755 index 0000000..39b70d1 --- /dev/null +++ b/scripts/mdToPdf @@ -0,0 +1,10 @@ +#!/bin/bash + +pandoc "$1" \ + -f gfm \ + -V linkcolor:blue \ + -V geometry:a4paper \ + -V geometry:margin=2cm \ + -V mainfont="Droid Sans" \ + --pdf-engine=xelatex \ + -o "$2" \ No newline at end of file diff --git a/scripts/rofi/config-selector.py b/scripts/rofi/config-selector.py new file mode 100755 index 0000000..195ade8 --- /dev/null +++ b/scripts/rofi/config-selector.py @@ -0,0 +1,20 @@ +#!/bin/python3 + +from subprocess import Popen, PIPE +from os.path import expandvars + +def call_rofi(entries,command): + proc = Popen(command, + stdin=PIPE, + stdout=PIPE) + for e in entries: + proc.stdin.write((e+"\n").encode('utf-8')) + proc.stdin.close() + answer = proc.stdout.read().decode('utf-8') + return answer.replace("\n","") + +with open('$HOME/.scripts/rofi/configfiles', 'r') as file: + choices = dict([(file.capitalize(), path) for file, path in [line.split(' ') for line in file.readlines()]]) + choice = call_rofi(choices, ['rofi', '-dmenu','-i', '-matching', 'fuzzy', '-p', 'Configfile']) + print(expandvars(choices[choice]), end='') + diff --git a/scripts/tmux/fcitx b/scripts/tmux/fcitx new file mode 100755 index 0000000..fb73a21 --- /dev/null +++ b/scripts/tmux/fcitx @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + + +printState() { + # REQUIRES QT5-TOOLS + STATUS=$(qdbus "org.fcitx.Fcitx" "/inputmethod" "GetCurrentIM") + + case $STATUS in + fcitx-keyboard-us) + echo 'US' + ;; + fcitx-keyboard-no) + echo 'NO' + ;; + mozc) + echo '日本語' + ;; + *) + echo "$STATUS?" + ;; + esac +} + +while : +do + printState + sleep 1 +done diff --git a/scripts/tmux/mpd b/scripts/tmux/mpd new file mode 100755 index 0000000..9dea8ce --- /dev/null +++ b/scripts/tmux/mpd @@ -0,0 +1,18 @@ +#!/bin/sh + +isPlaying() { +if mpc status | grep playing >/dev/null +then + echo -e "▶" +else + echo -e "⏸" +fi +} + +while true; do + PLAYING=$(isPlaying) + TITLE=$(mpc --format '[%artist% - ]%title%' | /usr/bin/head -n 1) + TIME=$(mpc | awk '(NR==2){print $3}') + echo -e "$PLAYING $TITLE | [$TIME]" + sleep 1 +done diff --git a/scripts/toCbz b/scripts/toCbz new file mode 100755 index 0000000..5fb4fd1 --- /dev/null +++ b/scripts/toCbz @@ -0,0 +1,6 @@ +#!/bin/bash +# Convert manga picture folders in current folder to cbz + +for i in ./*; do + zip -r "$i.cbz" "$i" +done diff --git a/scripts/touchpadToggle.sh b/scripts/touchpadToggle.sh new file mode 100755 index 0000000..301327c --- /dev/null +++ b/scripts/touchpadToggle.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +declare -i ID +ID=`xinput list | grep -Eio '(touchpad|glidepoint)\s*id\=[0-9]{1,2}' | grep -Eo '[0-9]{1,2}'` +declare -i STATE +STATE=`xinput list-props $ID|grep 'Device Enabled'|awk '{print $4}'` +if [ $STATE -eq 1 ] +then + xinput disable $ID + # echo "Touchpad disabled." + # notify-send -a 'Touchpad' 'Disabled' -i input-touchpad +else + xinput enable $ID + # echo "Touchpad enabled." + # notify-send -a 'Touchpad' 'Enabled' -i input-touchpad +fi