feat: add doc for bin folder

This commit is contained in:
Klesh Wong 2021-08-28 22:16:37 +08:00
parent e5f8b80b7b
commit dded5c94b8
18 changed files with 98 additions and 477 deletions

View File

@ -1,11 +1,82 @@
# dotfiles
* openurl copy move to dmenu
* auto install dict.sh
# About
OS / Software / Tools setup scripts to my personal taste, might not suit your need but welcome to COPY and Paste.
# How to use
# Directory
1. fork this repo
2. run installation script base on your need
3. customize to your taste and sync to your own repo
```sh
├── bin # useful scripts
├── cli # cli tools setup scripts
├── devel # development tools setup scripts
├── doc # setup document for those can't be automated
├── env.sh # common env detection for cli/gui/devel setup scripts
├── gui # gui tools setup script
├── README.md
└── win # setup scripts for windows
```
# bin
- `a2h`
convert ascii doc to html with asciidocter
- `bm`
Simple bookmark opener, fuzzy search `~/.config/bookmarks.md` and open with default browser
- `br`
Replace REGEX with NEWSTR for multiple files listed from stdin
- `charfont`
Draw specified character with pango-view and see which font were actually used
- `dbe`
Dbeaver used to have this flicking issue, seems fixed (2021-08-28)
- `decrypt_dbeaver_passwords`
Just like the file name
- `dl_google_drive`
Download file with `wget` from google drive so proxy can be used
- `docker_registry_catalog`
List images on docker registry
- `download-yt-audio.sh`
Just like the file name
- `download-yt-playlist.sh`
Just like the file name
- `download-yt-video.sh`
Just like the file name
- `ffmpeghelper`
Some video editing operation for ffmpeg
- `font-patcher`
Modified from nerd font patcher
- `fr`
Replace REGEX with NEWSTR, show preview when ran with REP=1 EnvVar
- `generate_fontstyle`
Generate Bold/Italic style from for font who has only Normal style
- `groff_ttf.sh`
Generate font file from ttf that could be used by groff
- `htpasswd-entry`
Encode username/password to htpasswd format
- `ls_vsc_cache`
List vscode cache
- `mediacut`
Video editing script
- `mergesrt`
Merge multi language srt files into one
- `pinentry-wsl-ps1.sh`
Delegate gnupg password prompt to Windows host
- `print_colors`
Preview colors of console
- `rds`
Connect to a remote redis server through ssh server
- `s`
ssh wrapper to auto rename tmux window name
- `sc`
Screencast recording with ffmpeg
- `ubuntu-ssh-wakes-sleeping-hd.sh`
Script to fix ssh login waking up sleeping hard-drive on Ubuntu
- `unttc.sh`
Decompress ttc to ttfs
- `virt-install.sh`
Create a virtual machine with virsh
- `ws`
Send websocket request to host for debugging
- `wsl-win-path.sh`
Convert Windows path to WSL path
- `x-open`
Like `open` on `macOS` but cross platform

View File

@ -1,13 +0,0 @@
#!/bin/sh
# backup
kubectl get pv -A -o json | jq '.items[] | select(.spec.storageClassName == "sc-1-name" or .spec.storageClassName == "sc-2-name")' | jq -M 'del(.spec.claimRef)' > volumes.json
kubectl get pvc -A -o json | jq '.items[] | select(.spec.storageClassName == "sc-1-name" or .spec.storageClassName == "sc-2-name")' > claims.json
tar czf data.tar.gz /data
# restore
tar xzf data.tar.gz
kubectl create claims.json
kubectl create volumes.json

9
bin/bm
View File

@ -1,5 +1,14 @@
#!/bin/fish
# fuzzy bookmark opener, read links from `~/.config/bookmarks.md` to fzf/dmenu and then open selected links with
# default browser
# `~/.config/bookmarks.md` sample:
# ```markdown
# # email
# - [hotmail](https://hotmail.com)
# - [gmail](https://gmail.com)
# ```
set -q XDG_CONFIG_HOME; or set XDG_CONFIG_HOME ~/.config
set -q BOOKMARK_PATH; or set BOOKMARK_PATH $XDG_CONFIG_HOME/bookmarks.md
if set -q BOOKMARK_SEARCHER

1
bin/br
View File

@ -1,5 +1,6 @@
#!/bin/sh
# batch replace: echo file1\nfile2 | br <REGEX> <NEWSTR>
# rule 1: use single quote '
# rule 2: //// for literal /

View File

@ -1,3 +1,5 @@
#!/bin/sh
# draw input character with pango-view and see which font were actually used
FC_DEBUG=4 pango-view --font=monospace -t "$1" | grep family:

0
bin/dl_google_drive Normal file → Executable file
View File

0
bin/docker_registry_catalog Normal file → Executable file
View File

View File

@ -1,22 +0,0 @@
#!/bin/sh
if [ ! -f /tmp/docker.zip ]; then
echo "Please enter nextcloud hostname:"
read -r HOSTNAME
echo "Please enter nextcloud account:"
read -r ACCOUNT
echo "Please enter nextcloud password:"
stty -echo
read -r PASSWORD
stty echo
curl -u "$ACCOUNT:$PASSWORD" -Lo /tmp/docker.zip "https://$HOSTNAME:8443/index.php/apps/files/ajax/download.php?dir=%2F&files=docker"
fi
DEST_DIR=$HOME/Nextcloud
mkdir -p "$DEST_DIR"
7z x -o"$DEST_DIR" /tmp/docker.zip

View File

@ -1,5 +0,0 @@
#!/bin/sh
wmname LG3D
/home/klesh/Programs/idea-IC-203.7717.32/bin/idea.sh

View File

@ -1,3 +0,0 @@
#!/bin/sh
_JAVA_OPTIONS="-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel" java -jar ~/Programs/bin/jd-gui-1.6.6.jar

View File

@ -1,101 +0,0 @@
#!/bin/bash
set -e
MOUNT_PATH=${1-'/mnt/hgst3t'}
# find all umounted devices/partions and deal with them
rm -rf /tmp/umounted_devs
IFS=' '
NUM=1
lsblk --noheadings --raw | while read -ra INFO; do
DEV="${INFO[0]}"
SIZE="${INFO[3]}"
TYPE="${INFO[5]}"
MOUNT="${INFO[6]}"
# skip mounted entry
#blkid | grep -F "/dev/$DEV" > /dev/null && continue
echo " $NUM) /dev/$DEV $SIZE $TYPE" >> /tmp/umounted_devs
NUM=$(($NUM+1))
done
if [ ! -s /tmp/umounted_devs ]; then
echo "no operatable drive/partition found"
exit -1
fi
echo
echo Pick a drive/partition to process
echo
cat /tmp/umounted_devs
echo
read -p "Please enter the line number: " NUM
LINE=$(sed -n "${NUM}p" /tmp/umounted_devs)
IFS=' ' read LN DEV SIZE TYPE <<< $LINE
echo
echo You selected $TYPE $DEV with size of $SIZE
echo
init_drive() {
echo "g
n
1
y
w" | sudo fdisk $DEV
}
init_partition() {
echo formating partition $1
sudo umount $1 || true
sudo mkfs.exfat $1
}
mount_partition() {
# remove mounting record from fstab
sed "\#$MOUNT_PATH\s#d" /etc/fstab | sudo tee /etc/fstab
UUID=$(sudo blkid -s UUID -o value $1)
echo "UUID=$UUID $MOUNT_PATH exfat auto,user,rw,async 0 0" | sudo tee -a /etc/fstab
mkdir -p $MOUNT_PATH
sudo mount -a
mkdir -p $MOUNT_PATH/movies
sudo systemctl start transmission
sudo systemctl start smb
}
# disk selected
if [ "$TYPE" = "disk" ]; then
NUM=$(ls -l $DEV* | wc -l)
# alert if drive already has partition
if [ $NUM -gt 1 ]; then
read -p "partitions found on $DEV, are u sure to initialize this drive? [y/N]: " CONFIRM
[ "$CONFIRM" != 'y' ] && exit -1
fi
init_drive
# format newly created partition on that dev
PART=$(ls $DEV* | tail -1)
init_partition $PART
mount_partition $PART
# partition selected
elif [ "$TYPE" = "part" ]; then
# partition is unformatted
if [ -z "$(blkid $DEV)" ] ; then
init_partition $DEV
# partition is not exfat format
elif blkid $DEV | grep -Fv exfat > /dev/null; then
read -p "all data on $DEV will be destroyed, are u sure? [y/N]: " CONFIRM
[ "$CONFIRM" != 'y' ] && exit -1
init_partition $DEV
fi
# now, we known partition is exfat format
mount_partition $DEV
fi

6
bin/p
View File

@ -1,6 +0,0 @@
#!/bin/sh
PPWD=$(pwd)
trap "cd '$PPWD'" EXIT
cd ~/.password-store
find . -iname '*.gpg' | cut -c3- | sed 's/\.gpg$//g' | fzf | xargs pass -c

View File

@ -1,38 +0,0 @@
#!/bin/bash
# need exfat-utils on archlinux
set -e
# ensure target path is mounted
DRIVE_PATH=${1-'/mnt/hgst3t'}
if ! mountpoint -q -- "$DRIVE_PATH"; then
echo "$DRIVE_PATH is not mounted"
exit -1
fi
# get device
DEV=$(grep -F "$DRIVE_PATH" /proc/mounts | awk '{print $1}')
# stop services that might using this target drives
sudo systemctl stop transmission
sudo systemctl stop smb
if sudo lsof $DRIVE_PATH 2>/dev/null; then
$DRIVE_PATH is being used
exit -1
fi
# create archive index file
read -p "Please enter archive number: " NUM
[ "$NUM" -ne "$NUM" ] && echo $NUM is not a number && exit -1
tree -L 2 $DRIVE_PATH/movies > ~/hgst3t-$NUM.txt
# remove mounting record from fstab
sed "\#$DRIVE_PATH\s#d" /etc/fstab | sudo tee /etc/fstab
sudo umount $DRIVE_PATH
echo you can safely remove $DRIVE_PATH now

View File

@ -1,281 +0,0 @@
#!/bin/env python3
import gzip
import argparse
import re
import sys
import io
import os
from abc import ABC, abstractclassmethod, abstractmethod, abstractstaticmethod
from typing import List, TextIO
def extract_nerdfont_ranges(font_patcher: TextIO):
range_re = re.compile(r"'((Src|Sym)(Start|End))':\s*([xXA-Fa-f0-9]+|None)")
name_re = re.compile(r"'Name':\s+\"(.*?)\"")
for line in font_patcher:
results = range_re.findall(line)
if len(results) != 4:
continue
props = {r[0]: int(r[3], base=16) if r[3] != "None" else None for r in results}
r = (
props["SrcStart"] or props["SymStart"],
props["SrcEnd"] or props["SymEnd"],
)
if r != (0, 0):
m = name_re.search(line)
if not m:
raise Exception("unable to find name: %s" % line)
yield r[0], r[1], m[1]
class Scope(ABC):
comment_override = None
def __init__(self, ranges: List[tuple], output: TextIO):
self.ranges = ranges
self.length = len(ranges)
self.output = output
self.cursor = 0
self.escape_char = None
self.re = re.compile(self.pattern())
@property
def empty(self) -> bool:
return self.cursor >= self.length
@property
def current(self) -> tuple:
return self.ranges[self.cursor]
def pop(self) -> bool:
if self.empty:
return False
ss, se, comment = self.current
self.write_line(ss, se, self.comment_override or comment)
self.cursor += 1
def read_line(self, line: str) -> bool:
m = self.re.match(line)
if not m:
raise Exception("unkown line: " + line)
ts = int(m[1], base=16)
te = int(m[3], base=16) if m[3] else ts
while not self.empty and self.current[1] < ts:
self.pop()
if self.empty:
return True
ss, se, _ = self.current
# output no intersection
if te < ss:
return True
# dont output subset
if ts >= ss and te <= se:
return False
if ss <= te: # clip left intersection
self.write_line(ts, ss - 1, m[5])
if se <= te:
self.pop()
if ts <= se:
self.write_line(se + 1, te, m[5])
if se < ts:
return True
return False
def write_line(self, start: int = None, end: int = None, comment: str = None) -> None:
if end < start:
return
self.output.write(self.format(start, end, comment) + '\n')
@abstractmethod
def pattern(self) -> str:
pass
@abstractmethod
def format(self, start: int, end: int, arg: any) -> str:
pass
class CharmapScope(Scope):
def pattern(self) -> str:
return r'<U([A-Z0-9]+)>(..<U([A-Z0-9]+)>)?\s+(\S+)\s+(.*?)$'
def format(self, start: int, end: int, comment: str) -> str:
return "%s%s %s %s" % (
"<U%04X>" % start,
"..<U%04X>" % end if end > start else "",
"".join(map(lambda x: "%sx%02x" % (self.escape_char, x), chr(start).encode('utf-8'))),
comment,
)
class WidthScope(Scope):
comment_override = '2'
def pattern(self) -> str:
return r'<U([A-Z0-9]+)>(...<U([A-Z0-9]+)>)?(\s+)(\d+)$'
def format(self, start: int, end: int, comment: str) -> str:
return "%s%s\t%s" % (
"<U%04X>" % start,
"...<U%04X>" % end if end > start else "",
comment
)
def inject_nerdfont_ranges(ranges: List[tuple], textin: TextIO, textout: TextIO):
comment_char = None
keyword_re = re.compile(r'<(\w+)>\s+(\S+)\s*')
charmap_scope = CharmapScope(ranges, textout)
width_scope = WidthScope(ranges, textout)
scope = None
for line in textin:
line = line.strip()
if line.startswith("CHARMAP"):
scope = charmap_scope
elif line.startswith("WIDTH"):
scope = width_scope
elif line.startswith("END "):
while not scope.empty:
scope.pop()
scope = None
elif comment_char and line.startswith(comment_char):
pass
elif scope and not scope.empty:
if scope.read_line(line) is False:
continue
elif line:
m = keyword_re.match(line)
if m:
if m[1] == "comment_char":
comment_char = m[2]
elif m[1] == 'escape_char':
charmap_scope.escape_char = m[2]
textout.write(line + "\n")
def test():
TARGET = (
"<comment_char> %\n"
"<escape_char> /\n\n"
"CHARMAP\n"
"<U0000> /x00 no\n"
"<U0001>..<U0005> /x01 left\n"
"<U0006> /x06 subset\n"
"<U0007> /x07 subset\n"
"<U0008>..<U0009> /x08 right\n"
"<U4E00>..<U4E99> /xe4/xb8/x80 superset\n"
"<U5E00> /x00 gap\n"
"END CHARMAP\n"
"WIDTH\n"
"<U0000>...<U0004>\t0\n"
"<U6F00>...<U7FFF>\t1\n"
"END WIDTH\n"
)
ranges = [
(4, 8, "test"),
(0x4e03, 0x4e0a, "test2"),
(0x4F00, 0x4F00, "test3"),
(0x6F00, 0x6F00, "tail"),
]
EXPECT = (
"<comment_char> %\n"
"<escape_char> /\n\n"
"CHARMAP\n"
"<U0000> /x00 no\n"
"<U0001>..<U0003> /x01 left\n"
"<U0004>..<U0008> /x04 test\n"
"<U0009> /x09 right\n"
"<U4E00>..<U4E02> /xe4/xb8/x80 superset\n"
"<U4E03>..<U4E0A> /xe4/xb8/x83 test2\n"
"<U4E0B>..<U4E99> /xe4/xb8/x8b superset\n"
"<U4F00> /xe4/xbc/x80 test3\n"
"<U5E00> /x00 gap\n"
"<U6F00> /xe6/xbc/x80 tail\n"
"END CHARMAP\n"
"WIDTH\n"
"<U0000>...<U0003>\t0\n"
"<U0004>...<U0008>\t2\n"
"<U4E03>...<U4E0A>\t2\n"
"<U4F00>\t2\n"
"<U6F00>\t2\n"
"<U6F01>...<U7FFF>\t1\n"
"END WIDTH\n"
)
target = io.StringIO(TARGET)
result = io.StringIO()
inject_nerdfont_ranges(ranges, target, result)
if result.getvalue() != EXPECT:
print("\033[42m origin\033[0m")
print(TARGET)
print()
print("\033[42m inject\033[0m")
for r in ranges:
print("%04X %04X %s" % r)
print()
print("\033[42m expect \033[0m", len(EXPECT))
print(EXPECT)
print()
print("\033[42m result \033[0m", len(result.getvalue()))
a = EXPECT.split('\n')
b = result.getvalue().split('\n')
for i in range(max(len(a), len(b))):
print("\033[%dm%s\033[0m" % (32 if a[i] == b[i] else 31, b[i]))
else:
print("pass")
if __name__ == "__main__":
if os.environ.get('DEBUGGING') == '1':
test()
else:
parser = argparse.ArgumentParser(
description="patch charmap to make NerdFont icons double width"
)
parser.add_argument(
"-i", "--in-charmap",
dest="in_charmap",
default="/usr/share/i18n/charmaps/UTF-8.gz",
help="input charmap file path")
parser.add_argument(
"-o", "--out",
dest="out_charmap",
default="/usr/share/i18n/charmaps/UTF-8NF.gz",
help="output charmap file path")
parser.add_argument(
"-f", "--font-patcher",
dest="font_patcher",
required=True,
help="file path of font_patcher from NerdFont")
parser.add_argument(
"--plainout",
dest="plainout",
action="store_true",
help="write to stdout in plain-text")
args = parser.parse_args()
font_patcher = open(args.font_patcher, 'r',)
double_width_ranges = extract_nerdfont_ranges(font_patcher)
in_charmap = gzip.open(args.in_charmap, 'rt', encoding="ascii")
if args.plainout:
out_charmap = sys.stdout
elif args.out_charmap.endswith('.gz'):
out_charmap = gzip.open(args.out_charmap, 'wt')
else:
out_charmap = open(args.out_charmap, 'wt')
ranges = sorted(
filter(lambda x: x[2] in ['Seti-UI + Custom', 'Devicons'], double_width_ranges),
key=lambda x: x[0]
)
for r in ranges:
print("%04X-%04X %s" % r)
inject_nerdfont_ranges(ranges, in_charmap, out_charmap)
# add `en_US.UTF-8NF UTF-8NF` to `/etc/locale.gen`
# run `locale-gen`
# update `/etc/locale.conf` to `LANG=en_US.UTF-8NF`
# restart

View File

@ -9,3 +9,4 @@ map \cg eval import subprocess;fm.cd(subprocess.getoutput('git rev-parse --show-
map <C-t> fzf_select
map <C-p> fzf_edit
map oo mediacut_open
map x shell chmod +x %s

View File

@ -44,7 +44,7 @@ case "$PM" in
pacman)
# TODO
sudo pacman -S --noconfirm --needed \
qemu libvirt virt-manager
ebtables dnsmasq qemu libvirt virt-manager
;;
esac

6
doc/FAQ.md Normal file
View File

@ -0,0 +1,6 @@
# FAQ
## Linux sleep crashes for amd cpu
1. Edit `/etc/default/grub`: add `amd_iommu=off` to `GRUB_CMDLINE_LINUX_DEFAULT`
2. Save, and run `sudo grub-mkconfig -o /boot/grub/grub.cfg`
3. Reboot