mirror of
https://github.com/notwa/rc
synced 2024-05-18 17:53:23 -07:00
overhaul
This commit is contained in:
parent
b1f7cdd3f5
commit
5eaf74401e
489
README-old.md
Normal file
489
README-old.md
Normal file
|
@ -0,0 +1,489 @@
|
||||||
|
## obligatory personal dotfiles repository
|
||||||
|
|
||||||
|
_(plus some little shell scripts)_
|
||||||
|
|
||||||
|
quick install for random boxes:
|
||||||
|
|
||||||
|
```
|
||||||
|
cd && curl -L https://github.com/notwa/rc/archive/master.tar.gz | tar zx && mv rc-master rc && rc/install
|
||||||
|
```
|
||||||
|
|
||||||
|
## stuff defined in RC files
|
||||||
|
|
||||||
|
such as [.bashrc](/home/bashrc) and [.zshrc](/home/zshrc)
|
||||||
|
but mostly [-shrc](/home/-shrc) and [.streamcrap](/home/streamcrap)
|
||||||
|
|
||||||
|
### reload
|
||||||
|
|
||||||
|
exec's the current shell.
|
||||||
|
if it's `zsh`, it'll also recompile `.zshrc` so everything actually reloads.
|
||||||
|
|
||||||
|
### ADDPATH
|
||||||
|
|
||||||
|
adds a directory to `$PATH` if it isn't already there.
|
||||||
|
|
||||||
|
### ify
|
||||||
|
|
||||||
|
pipes a command through another command, so you can pass arguments at the end as usual.
|
||||||
|
|
||||||
|
this is mainly useful for aliases. 99% of the time you'll use this with `less`.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ alias ll="ify less ls -ACX --group-directories-first --color=force"
|
||||||
|
$ ll /etc
|
||||||
|
```
|
||||||
|
|
||||||
|
### has
|
||||||
|
|
||||||
|
prints the result of `which` if the program is found, or shuts up and returns 1.
|
||||||
|
|
||||||
|
```
|
||||||
|
export CC="$(has clang || has clang-3.8 || has gcc)"
|
||||||
|
```
|
||||||
|
|
||||||
|
### revend
|
||||||
|
|
||||||
|
reverses the 4-byte endianness of a file. this is an in-place operation!
|
||||||
|
|
||||||
|
### nocom
|
||||||
|
|
||||||
|
strips lines that begin with a `#` character.
|
||||||
|
|
||||||
|
### jrep
|
||||||
|
|
||||||
|
extracts ascii and japanese unicode characters.
|
||||||
|
|
||||||
|
### bomb
|
||||||
|
|
||||||
|
adds a Byte Order Mark to a file.
|
||||||
|
|
||||||
|
### cleanse
|
||||||
|
|
||||||
|
extracts readable ascii characters.
|
||||||
|
|
||||||
|
### rot13
|
||||||
|
|
||||||
|
rot13 with rotated numbers as well.
|
||||||
|
|
||||||
|
### unwrap
|
||||||
|
|
||||||
|
unwraps text that was wrapped using double-newlines as spacing,
|
||||||
|
e.g. this readme file.
|
||||||
|
|
||||||
|
### double
|
||||||
|
|
||||||
|
prints every line twice.
|
||||||
|
prints every line twice.
|
||||||
|
|
||||||
|
### join2
|
||||||
|
|
||||||
|
joins every other line.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ echo "hey\nyou\nout there\nwe bringing it live" | join2
|
||||||
|
hey you
|
||||||
|
out there we bringing it live
|
||||||
|
```
|
||||||
|
|
||||||
|
### katagana
|
||||||
|
|
||||||
|
converts katakana to hiragana.
|
||||||
|
useful for translating [debug text from ancient games.](https://tcrf.net/)
|
||||||
|
|
||||||
|
### picky + unused
|
||||||
|
|
||||||
|
attempts to find any non-standard packages that were installed
|
||||||
|
with pacman so that you can make note to install them, later,
|
||||||
|
on a fresh installation.
|
||||||
|
|
||||||
|
`unused` will print unused packages instead.
|
||||||
|
|
||||||
|
### makepkgf + rakef
|
||||||
|
|
||||||
|
make the freakin' package!
|
||||||
|
|
||||||
|
### trash
|
||||||
|
|
||||||
|
given a number of bytes, outputs binary garbage from `/dev/random`.
|
||||||
|
|
||||||
|
### wipe
|
||||||
|
|
||||||
|
(zsh) clears the screen and scrollback and prints an ugly horizontal line,
|
||||||
|
so you know with absolute certainty that you're looking
|
||||||
|
at the top of your history, and that your terminal's scrollback
|
||||||
|
didn't cap out and eat text.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ wipe; ./configure && make
|
||||||
|
[insert a bajillion lines you'd never be able to find the top of unless
|
||||||
|
you piped it to a file or less or wiped scrollback beforehand]
|
||||||
|
```
|
||||||
|
|
||||||
|
### yt
|
||||||
|
|
||||||
|
watches a youtube video through mpv with a bunch of audio filtering crap.
|
||||||
|
|
||||||
|
can be given a full URL or just a video ID.
|
||||||
|
remaining arguments are passed to mpv.
|
||||||
|
|
||||||
|
there exist several other variants for specific use cases.
|
||||||
|
|
||||||
|
### twitch
|
||||||
|
|
||||||
|
watches twitch streams through mpv with a bunch of audio filtering crap.
|
||||||
|
|
||||||
|
give it a username.
|
||||||
|
remaining arguments are passed to mpv.
|
||||||
|
|
||||||
|
## shell scripts
|
||||||
|
|
||||||
|
most (but not all) stuff that's written for bash will work in zsh too.
|
||||||
|
if it just says `(sh)` then it'll probably work on any shell,
|
||||||
|
but might depend on GNU awk.
|
||||||
|
|
||||||
|
[prezto]: https://github.com/sorin-ionescu/prezto
|
||||||
|
|
||||||
|
### [arith](/sh/arith) + [hex](/sh/hex)
|
||||||
|
|
||||||
|
(zsh) does arithmetic using the shell.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ noglob arith 10**(6/20.)
|
||||||
|
1.9952623149688795
|
||||||
|
$ hex 0x221EA8-0x212020
|
||||||
|
0000FE88
|
||||||
|
```
|
||||||
|
|
||||||
|
### [aur](/sh/aur)
|
||||||
|
|
||||||
|
(bash) downloads, edits, makes, and installs packages from the [AUR.](//aur.archlinux.org)
|
||||||
|
|
||||||
|
it's a little broken.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ aur -eyoI cmdpack-uips applyppf
|
||||||
|
```
|
||||||
|
|
||||||
|
### [autosync](/sh/autosync)
|
||||||
|
|
||||||
|
(zsh) combines inotifywait and rsync.
|
||||||
|
|
||||||
|
sometimes nicer than ssh-ing into a server and running vim remotely.
|
||||||
|
|
||||||
|
### [cdbusiest](/sh/cdbusiest) + [dbusiest](/sh/dbusiest)
|
||||||
|
|
||||||
|
(zsh) cd to the directory with the most files in it (recursive).
|
||||||
|
dbusiest just outputs file counts without changing the directory.
|
||||||
|
|
||||||
|
useful for finding the biggest stinkers when archiving.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ cd
|
||||||
|
$ cdbusiest
|
||||||
|
197195 src
|
||||||
|
$ pwd
|
||||||
|
/home/notwa/src
|
||||||
|
```
|
||||||
|
|
||||||
|
### [colors](/sh/colors)
|
||||||
|
|
||||||
|
(bash) print out all the foreground and background terminal color combinations.
|
||||||
|
a 76-character script!
|
||||||
|
|
||||||
|
### [compandy](/sh/compandy)
|
||||||
|
|
||||||
|
(zsh) a dumb thing to generate compand arguments for ffmpeg audio filters.
|
||||||
|
|
||||||
|
kinda pointless now that acompressor is wildly supported.
|
||||||
|
|
||||||
|
### [compile](/sh/compile)
|
||||||
|
|
||||||
|
(zsh) a huge mess for compiling single-file C and C++ programs.
|
||||||
|
|
||||||
|
supports gcc and clang on \*nix,
|
||||||
|
and mingw64 gcc, msvc clang, and regular msvc on Windows.
|
||||||
|
tested on x86\_64 and on ARMv7 as well.
|
||||||
|
does not support MacOS, maybe someday…
|
||||||
|
|
||||||
|
defaults to gnu11 and gnu++1z as C and C++ standards respectively.
|
||||||
|
defaults to clang, gcc, and msvc in that order.
|
||||||
|
|
||||||
|
`compile` attempts to guess the most sane switches for any program,
|
||||||
|
so that compilation may reduce to:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# debug build
|
||||||
|
compile rd.c
|
||||||
|
compile debug rd.c
|
||||||
|
# debug build with warning/error flags defined in .-shrc
|
||||||
|
# (requires .zshrc for global alias expansion)
|
||||||
|
compile WHOA rd.c
|
||||||
|
# likewise for C++
|
||||||
|
compile WHOA WELP rd.cc
|
||||||
|
compile WHOA WELP rd.cpp
|
||||||
|
# "derelease" build (release build with debug information)
|
||||||
|
compile derelease WHOA rd.c
|
||||||
|
# release build (with symbols stripped)
|
||||||
|
compile release WHOA rd.c
|
||||||
|
# hardened build (only useful on *nix)
|
||||||
|
compile hardened WHOA rd.c
|
||||||
|
# specifying compiler
|
||||||
|
compile gcc WHOA rd.c
|
||||||
|
compile msvc WHOA rd.c
|
||||||
|
compile release clang WHOA rd.c
|
||||||
|
# compile and execute (FIXME: writing to /tmp is a security concern)
|
||||||
|
compile derelease rd.c && /tmp/rd
|
||||||
|
```
|
||||||
|
|
||||||
|
also contains a helper function that dumps the commands required to
|
||||||
|
install a recent version of clang on an ubuntu machine.
|
||||||
|
|
||||||
|
### [confirm](/sh/confirm)
|
||||||
|
|
||||||
|
(bash/zsh) displays a simple yes/no prompt and returns 0 or 1 respectively.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ confirm && echo yay || echo nay
|
||||||
|
Continue? [y/N] y
|
||||||
|
yay
|
||||||
|
$ confirm && echo yay || echo nay
|
||||||
|
Continue? [y/N] n
|
||||||
|
nay
|
||||||
|
```
|
||||||
|
|
||||||
|
### [days](/sh/days)
|
||||||
|
|
||||||
|
(bash) compute days since a date.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ days 'January 1 1970'
|
||||||
|
17229
|
||||||
|
```
|
||||||
|
|
||||||
|
### [dfu](/sh/dfu)
|
||||||
|
|
||||||
|
(sh) pretty-print `df` in GiB.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ dfu
|
||||||
|
Filesystem Used Max Left Misc
|
||||||
|
/dev 0.00 0.45 0.45 0.00
|
||||||
|
/ 12.13 13.75 1.62 0.75
|
||||||
|
/boot 0.02 0.10 0.07 0.00
|
||||||
|
/media/chibi 1275.73 1304.45 28.72 69.88
|
||||||
|
```
|
||||||
|
|
||||||
|
### [disf](/sh/disf)
|
||||||
|
|
||||||
|
disassembles a single function from an unstripped executable.
|
||||||
|
not robust.
|
||||||
|
|
||||||
|
### [e](/sh/e)
|
||||||
|
|
||||||
|
(zsh) wraps around $EDITOR to run as root if necessary.
|
||||||
|
this still needs some work to detect root-owned directories.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ e /etc/sudoers
|
||||||
|
[sudo] password for notwa:
|
||||||
|
```
|
||||||
|
|
||||||
|
### [is\_empty](/sh/is_empty)
|
||||||
|
|
||||||
|
(bash) returns 0 if the directory given by $1 is empty.
|
||||||
|
|
||||||
|
### [isup](/sh/isup)
|
||||||
|
|
||||||
|
(zsh) returns 0 if a website returns a 2xx HTTP code.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ isup google.com && echo yay || echo nay
|
||||||
|
yay
|
||||||
|
$ isup fdhafdslkjgfjs.com && echo yay || echo nay
|
||||||
|
nay
|
||||||
|
```
|
||||||
|
|
||||||
|
### [lsarchive](/sh/lsarchive) + [unarchive](/sh/unarchive)
|
||||||
|
|
||||||
|
(zsh) guess what these do. [via prezto.][prezto]
|
||||||
|
includes autocomplete files.
|
||||||
|
|
||||||
|
### [minutemaid](/sh/minutemaid)
|
||||||
|
|
||||||
|
(zsh) returns 0 if the current minute is divisible by a number.
|
||||||
|
|
||||||
|
note that a minute is relative to the seconds since the epoch,
|
||||||
|
not the minute of the hour.
|
||||||
|
|
||||||
|
```
|
||||||
|
# crontab usage:
|
||||||
|
* * * * * minutemaid 9 cd repo && git pull # runs every nine minutes
|
||||||
|
```
|
||||||
|
|
||||||
|
### [monitor](/sh/monitor)
|
||||||
|
|
||||||
|
(zsh) basically just `watch` reimplemented as a shell script. kinda nice though.
|
||||||
|
|
||||||
|
### [now](/sh/now)
|
||||||
|
|
||||||
|
(bash) prints a date-time (UTC) in a sortable format.
|
||||||
|
it takes a date or file as an argument,
|
||||||
|
else defaults to the current time.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ now
|
||||||
|
2019-05-27_35083906
|
||||||
|
$ now ~/sh/monitor
|
||||||
|
2017-03-14_82387259
|
||||||
|
$ now '@1234567890'
|
||||||
|
2009-02-13_84690000
|
||||||
|
```
|
||||||
|
|
||||||
|
### [pacbm](/sh/pacbm)
|
||||||
|
|
||||||
|
(zsh) lists installed pacman packages by their filesize, and the sum, ascending.
|
||||||
|
requires `expac`.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ pacbm | head -n -1 | tail -2
|
||||||
|
204.78M clang
|
||||||
|
235.44M linux-firmware
|
||||||
|
```
|
||||||
|
|
||||||
|
### [pacman-list-disowned](/sh/pacman-list-disowned)
|
||||||
|
|
||||||
|
(zsh?) lists disowned pacman files. this might take a while.
|
||||||
|
[via prezto.][prezto]
|
||||||
|
|
||||||
|
### [pause](/sh/pause)
|
||||||
|
|
||||||
|
(bash/zsh) pause; the companion script of `confirm`.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ pause
|
||||||
|
Press any key to continue
|
||||||
|
$
|
||||||
|
```
|
||||||
|
|
||||||
|
### [pre](/sh/pre)
|
||||||
|
|
||||||
|
(bash/zsh) dumps all the #defines that `$CC $CPPFLAGS $CFLAGS $LDFLAGS` would result in.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ pre | shuf | head -10
|
||||||
|
#define __NO_MATH_INLINES 1
|
||||||
|
#define __FLT_MIN_10_EXP__ (-37)
|
||||||
|
#define __INT_LEAST32_TYPE__ int
|
||||||
|
#define __FLT_MIN_EXP__ (-125)
|
||||||
|
#define __LDBL_MIN_EXP__ (-16381)
|
||||||
|
#define __UINT8_C_SUFFIX__
|
||||||
|
#define __WINT_UNSIGNED__ 1
|
||||||
|
#define __INT_LEAST16_FMTd__ "hd"
|
||||||
|
#define __UINT_FAST32_MAX__ 4294967295U
|
||||||
|
#define __SSE__ 1
|
||||||
|
```
|
||||||
|
|
||||||
|
### [psbm](/sh/psbm)
|
||||||
|
|
||||||
|
(sh) lists processes by their memory usage, and the sum, ascending.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ psbm | head -n -1 | tail -2
|
||||||
|
185.08M 1163 chromium
|
||||||
|
199.95M 1060 chromium
|
||||||
|
```
|
||||||
|
|
||||||
|
### [randir](/sh/randir)
|
||||||
|
|
||||||
|
(sh) outputs a random directory in the working directory.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ randir
|
||||||
|
./sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### [rs](/sh/rs)
|
||||||
|
|
||||||
|
(zsh) record screen. does not record audio.
|
||||||
|
|
||||||
|
currently only works on Windows (gdigrab).
|
||||||
|
i'm sure there's something equivalent for Linux.
|
||||||
|
|
||||||
|
### [sc](/sh/sc)
|
||||||
|
|
||||||
|
(bash) uploads given files to a webserver and returns a direct link for sharing.
|
||||||
|
you'll want to tweak this if you use it yourself.
|
||||||
|
|
||||||
|
has some extra logic for screenshots created by `scropt`.
|
||||||
|
|
||||||
|
### [scramble](/sh/sc)
|
||||||
|
|
||||||
|
(bash) scrambles text in a predictable way using regex.
|
||||||
|
|
||||||
|
(bhas) sacbremls ttex in a pdrceailtbe way unsig reegx.
|
||||||
|
|
||||||
|
### [screeny](/sh/screeny) + [unscreen](/sh/unscreen)
|
||||||
|
|
||||||
|
(zsh) sets up and detaches a screen for running daemons as other users, etc.
|
||||||
|
|
||||||
|
this will close any existing screens of the same name using its companion script, unscreen.
|
||||||
|
|
||||||
|
e.g. run znc as user znc in a screen called znc: `screeny znc znc znc -f`. znc!
|
||||||
|
|
||||||
|
<!--(you should really just use tmux though)-->
|
||||||
|
|
||||||
|
### [scropt](/sh/scropt)
|
||||||
|
|
||||||
|
(bash) runs `scrot` through `optipng` and saves to `~/play/$(now).png`.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ ~/sh/sc $(~/sh/scropt -s -d0.5)
|
||||||
|
```
|
||||||
|
|
||||||
|
### [similar](/sh/similar)
|
||||||
|
|
||||||
|
(sh) highlights similarities between adjacent lines.
|
||||||
|
|
||||||
|
### [slit](/sh/slit) + [slitt](/sh/slitt)
|
||||||
|
|
||||||
|
(zsh) views specific columns of text.
|
||||||
|
[via pretzo.][prezto]
|
||||||
|
|
||||||
|
```
|
||||||
|
$ df | slit 1 5
|
||||||
|
Filesystem Use%
|
||||||
|
dev 0%
|
||||||
|
run 1%
|
||||||
|
/dev/sda6 30%
|
||||||
|
tmpfs 3%
|
||||||
|
tmpfs 0%
|
||||||
|
tmpfs 1%
|
||||||
|
tmpfs 1%
|
||||||
|
```
|
||||||
|
|
||||||
|
`slitt` is exactly the same, but it works with tabs instead of spaces.
|
||||||
|
|
||||||
|
### [sram](/sh/sram)
|
||||||
|
|
||||||
|
(zsh) converts between a couple saveram formats for N64 emulators.
|
||||||
|
|
||||||
|
### [sv](/sh/sv)
|
||||||
|
|
||||||
|
(bash) collects the lastmost value of every key.
|
||||||
|
takes the field separator as an argument.
|
||||||
|
|
||||||
|
```
|
||||||
|
echo "this=that\nthem=those\nthis=cat" | sv =
|
||||||
|
this=cat
|
||||||
|
them=those
|
||||||
|
```
|
||||||
|
|
||||||
|
### [tpad](/sh/tpad)
|
||||||
|
|
||||||
|
(bash) adds a 1px transparent border around an image
|
||||||
|
so that twitter doesn't mangle it into a jpg.
|
||||||
|
sadly, this trick doesn't work anymore.
|
||||||
|
|
||||||
|
### [trunc](/sh/trunc)
|
||||||
|
|
||||||
|
(bash) truncates text to fit within your terminal using the unicode character `…`.
|
476
README.md
476
README.md
|
@ -10,480 +10,8 @@ cd && curl -L https://github.com/notwa/rc/archive/master.tar.gz | tar zx && mv r
|
||||||
|
|
||||||
## stuff defined in RC files
|
## stuff defined in RC files
|
||||||
|
|
||||||
such as [.bashrc](/home/bashrc) and [.zshrc](/home/zshrc)
|
hold on, this needs to be rewritten.
|
||||||
but mostly [-shrc](/home/-shrc) and [.streamcrap](/home/streamcrap)
|
|
||||||
|
|
||||||
### reload
|
|
||||||
|
|
||||||
exec's the current shell.
|
|
||||||
if it's `zsh`, it'll also recompile `.zshrc` so everything actually reloads.
|
|
||||||
|
|
||||||
### ADDPATH
|
|
||||||
|
|
||||||
adds a directory to `$PATH` if it isn't already there.
|
|
||||||
|
|
||||||
### ify
|
|
||||||
|
|
||||||
pipes a command through another command, so you can pass arguments at the end as usual.
|
|
||||||
|
|
||||||
this is mainly useful for aliases. 99% of the time you'll use this with `less`.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ alias ll="ify less ls -ACX --group-directories-first --color=force"
|
|
||||||
$ ll /etc
|
|
||||||
```
|
|
||||||
|
|
||||||
### has
|
|
||||||
|
|
||||||
prints the result of `which` if the program is found, or shuts up and returns 1.
|
|
||||||
|
|
||||||
```
|
|
||||||
export CC="$(has clang || has clang-3.8 || has gcc)"
|
|
||||||
```
|
|
||||||
|
|
||||||
### revend
|
|
||||||
|
|
||||||
reverses the 4-byte endianness of a file. this is an in-place operation!
|
|
||||||
|
|
||||||
### nocom
|
|
||||||
|
|
||||||
strips lines that begin with a `#` character.
|
|
||||||
|
|
||||||
### jrep
|
|
||||||
|
|
||||||
extracts ascii and japanese unicode characters.
|
|
||||||
|
|
||||||
### bomb
|
|
||||||
|
|
||||||
adds a Byte Order Mark to a file.
|
|
||||||
|
|
||||||
### cleanse
|
|
||||||
|
|
||||||
extracts readable ascii characters.
|
|
||||||
|
|
||||||
### rot13
|
|
||||||
|
|
||||||
rot13 with rotated numbers as well.
|
|
||||||
|
|
||||||
### unwrap
|
|
||||||
|
|
||||||
unwraps text that was wrapped using double-newlines as spacing,
|
|
||||||
e.g. this readme file.
|
|
||||||
|
|
||||||
### double
|
|
||||||
|
|
||||||
prints every line twice.
|
|
||||||
prints every line twice.
|
|
||||||
|
|
||||||
### join2
|
|
||||||
|
|
||||||
joins every other line.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ echo "hey\nyou\nout there\nwe bringing it live" | join2
|
|
||||||
hey you
|
|
||||||
out there we bringing it live
|
|
||||||
```
|
|
||||||
|
|
||||||
### katagana
|
|
||||||
|
|
||||||
converts katakana to hiragana.
|
|
||||||
useful for translating [debug text from ancient games.](https://tcrf.net/)
|
|
||||||
|
|
||||||
### picky + unused
|
|
||||||
|
|
||||||
attempts to find any non-standard packages that were installed
|
|
||||||
with pacman so that you can make note to install them, later,
|
|
||||||
on a fresh installation.
|
|
||||||
|
|
||||||
`unused` will print unused packages instead.
|
|
||||||
|
|
||||||
### makepkgf + rakef
|
|
||||||
|
|
||||||
make the freakin' package!
|
|
||||||
|
|
||||||
### trash
|
|
||||||
|
|
||||||
given a number of bytes, outputs binary garbage from `/dev/random`.
|
|
||||||
|
|
||||||
### wipe
|
|
||||||
|
|
||||||
(zsh) clears the screen and scrollback and prints an ugly horizontal line,
|
|
||||||
so you know with absolute certainty that you're looking
|
|
||||||
at the top of your history, and that your terminal's scrollback
|
|
||||||
didn't cap out and eat text.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ wipe; ./configure && make
|
|
||||||
[insert a bajillion lines you'd never be able to find the top of unless
|
|
||||||
you piped it to a file or less or wiped scrollback beforehand]
|
|
||||||
```
|
|
||||||
|
|
||||||
### yt
|
|
||||||
|
|
||||||
watches a youtube video through mpv with a bunch of audio filtering crap.
|
|
||||||
|
|
||||||
can be given a full URL or just a video ID.
|
|
||||||
remaining arguments are passed to mpv.
|
|
||||||
|
|
||||||
there exist several other variants for specific use cases.
|
|
||||||
|
|
||||||
### twitch
|
|
||||||
|
|
||||||
watches twitch streams through mpv with a bunch of audio filtering crap.
|
|
||||||
|
|
||||||
give it a username.
|
|
||||||
remaining arguments are passed to mpv.
|
|
||||||
|
|
||||||
## shell scripts
|
## shell scripts
|
||||||
|
|
||||||
most (but not all) stuff that's written for bash will work in zsh too.
|
hold on, this needs to be rewritten.
|
||||||
if it just says `(sh)` then it'll probably work on any shell,
|
|
||||||
but might depend on GNU awk.
|
|
||||||
|
|
||||||
[prezto]: https://github.com/sorin-ionescu/prezto
|
|
||||||
|
|
||||||
### [arith](/sh/arith) + [hex](/sh/hex)
|
|
||||||
|
|
||||||
(zsh) does arithmetic using the shell.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ noglob arith 10**(6/20.)
|
|
||||||
1.9952623149688795
|
|
||||||
$ hex 0x221EA8-0x212020
|
|
||||||
0000FE88
|
|
||||||
```
|
|
||||||
|
|
||||||
### [aur](/sh/aur)
|
|
||||||
|
|
||||||
(bash) downloads, edits, makes, and installs packages from the [AUR.](//aur.archlinux.org)
|
|
||||||
|
|
||||||
it's a little broken.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ aur -eyoI cmdpack-uips applyppf
|
|
||||||
```
|
|
||||||
|
|
||||||
### [autosync](/sh/autosync)
|
|
||||||
|
|
||||||
(zsh) combines inotifywait and rsync.
|
|
||||||
|
|
||||||
sometimes nicer than ssh-ing into a server and running vim remotely.
|
|
||||||
|
|
||||||
### [cdbusiest](/sh/cdbusiest) + [dbusiest](/sh/dbusiest)
|
|
||||||
|
|
||||||
(zsh) cd to the directory with the most files in it (recursive).
|
|
||||||
dbusiest just outputs file counts without changing the directory.
|
|
||||||
|
|
||||||
useful for finding the biggest stinkers when archiving.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ cd
|
|
||||||
$ cdbusiest
|
|
||||||
197195 src
|
|
||||||
$ pwd
|
|
||||||
/home/notwa/src
|
|
||||||
```
|
|
||||||
|
|
||||||
### [colors](/sh/colors)
|
|
||||||
|
|
||||||
(bash) print out all the foreground and background terminal color combinations.
|
|
||||||
a 76-character script!
|
|
||||||
|
|
||||||
### [compandy](/sh/compandy)
|
|
||||||
|
|
||||||
(zsh) a dumb thing to generate compand arguments for ffmpeg audio filters.
|
|
||||||
|
|
||||||
kinda pointless now that acompressor is wildly supported.
|
|
||||||
|
|
||||||
### [compile](/sh/compile)
|
|
||||||
|
|
||||||
(zsh) a huge mess for compiling single-file C and C++ programs.
|
|
||||||
|
|
||||||
supports gcc and clang on \*nix,
|
|
||||||
and mingw64 gcc, msvc clang, and regular msvc on Windows.
|
|
||||||
tested on x86\_64 and on ARMv7 as well.
|
|
||||||
does not support MacOS, maybe someday…
|
|
||||||
|
|
||||||
defaults to gnu11 and gnu++1z as C and C++ standards respectively.
|
|
||||||
defaults to clang, gcc, and msvc in that order.
|
|
||||||
|
|
||||||
`compile` attempts to guess the most sane switches for any program,
|
|
||||||
so that compilation may reduce to:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
# debug build
|
|
||||||
compile rd.c
|
|
||||||
compile debug rd.c
|
|
||||||
# debug build with warning/error flags defined in .-shrc
|
|
||||||
# (requires .zshrc for global alias expansion)
|
|
||||||
compile WHOA rd.c
|
|
||||||
# likewise for C++
|
|
||||||
compile WHOA WELP rd.cc
|
|
||||||
compile WHOA WELP rd.cpp
|
|
||||||
# "derelease" build (release build with debug information)
|
|
||||||
compile derelease WHOA rd.c
|
|
||||||
# release build (with symbols stripped)
|
|
||||||
compile release WHOA rd.c
|
|
||||||
# hardened build (only useful on *nix)
|
|
||||||
compile hardened WHOA rd.c
|
|
||||||
# specifying compiler
|
|
||||||
compile gcc WHOA rd.c
|
|
||||||
compile msvc WHOA rd.c
|
|
||||||
compile release clang WHOA rd.c
|
|
||||||
# compile and execute (FIXME: writing to /tmp is a security concern)
|
|
||||||
compile derelease rd.c && /tmp/rd
|
|
||||||
```
|
|
||||||
|
|
||||||
also contains a helper function that dumps the commands required to
|
|
||||||
install a recent version of clang on an ubuntu machine.
|
|
||||||
|
|
||||||
### [confirm](/sh/confirm)
|
|
||||||
|
|
||||||
(bash/zsh) displays a simple yes/no prompt and returns 0 or 1 respectively.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ confirm && echo yay || echo nay
|
|
||||||
Continue? [y/N] y
|
|
||||||
yay
|
|
||||||
$ confirm && echo yay || echo nay
|
|
||||||
Continue? [y/N] n
|
|
||||||
nay
|
|
||||||
```
|
|
||||||
|
|
||||||
### [days](/sh/days)
|
|
||||||
|
|
||||||
(bash) compute days since a date.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ days 'January 1 1970'
|
|
||||||
17229
|
|
||||||
```
|
|
||||||
|
|
||||||
### [dfu](/sh/dfu)
|
|
||||||
|
|
||||||
(sh) pretty-print `df` in GiB.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ dfu
|
|
||||||
Filesystem Used Max Left Misc
|
|
||||||
/dev 0.00 0.45 0.45 0.00
|
|
||||||
/ 12.13 13.75 1.62 0.75
|
|
||||||
/boot 0.02 0.10 0.07 0.00
|
|
||||||
/media/chibi 1275.73 1304.45 28.72 69.88
|
|
||||||
```
|
|
||||||
|
|
||||||
### [disf](/sh/disf)
|
|
||||||
|
|
||||||
disassembles a single function from an unstripped executable.
|
|
||||||
not robust.
|
|
||||||
|
|
||||||
### [e](/sh/e)
|
|
||||||
|
|
||||||
(zsh) wraps around $EDITOR to run as root if necessary.
|
|
||||||
this still needs some work to detect root-owned directories.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ e /etc/sudoers
|
|
||||||
[sudo] password for notwa:
|
|
||||||
```
|
|
||||||
|
|
||||||
### [is\_empty](/sh/is_empty)
|
|
||||||
|
|
||||||
(bash) returns 0 if the directory given by $1 is empty.
|
|
||||||
|
|
||||||
### [isup](/sh/isup)
|
|
||||||
|
|
||||||
(zsh) returns 0 if a website returns a 2xx HTTP code.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ isup google.com && echo yay || echo nay
|
|
||||||
yay
|
|
||||||
$ isup fdhafdslkjgfjs.com && echo yay || echo nay
|
|
||||||
nay
|
|
||||||
```
|
|
||||||
|
|
||||||
### [lsarchive](/sh/lsarchive) + [unarchive](/sh/unarchive)
|
|
||||||
|
|
||||||
(zsh) guess what these do. [via prezto.][prezto]
|
|
||||||
includes autocomplete files.
|
|
||||||
|
|
||||||
### [minutemaid](/sh/minutemaid)
|
|
||||||
|
|
||||||
(zsh) returns 0 if the current minute is divisible by a number.
|
|
||||||
|
|
||||||
note that a minute is relative to the seconds since the epoch,
|
|
||||||
not the minute of the hour.
|
|
||||||
|
|
||||||
```
|
|
||||||
# crontab usage:
|
|
||||||
* * * * * minutemaid 9 cd repo && git pull # runs every nine minutes
|
|
||||||
```
|
|
||||||
|
|
||||||
### [monitor](/sh/monitor)
|
|
||||||
|
|
||||||
(zsh) basically just `watch` reimplemented as a shell script. kinda nice though.
|
|
||||||
|
|
||||||
### [now](/sh/now)
|
|
||||||
|
|
||||||
(bash) prints a date-time (UTC) in a sortable format.
|
|
||||||
it takes a date or file as an argument,
|
|
||||||
else defaults to the current time.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ now
|
|
||||||
2019-05-27_35083906
|
|
||||||
$ now ~/sh/monitor
|
|
||||||
2017-03-14_82387259
|
|
||||||
$ now '@1234567890'
|
|
||||||
2009-02-13_84690000
|
|
||||||
```
|
|
||||||
|
|
||||||
### [pacbm](/sh/pacbm)
|
|
||||||
|
|
||||||
(zsh) lists installed pacman packages by their filesize, and the sum, ascending.
|
|
||||||
requires `expac`.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ pacbm | head -n -1 | tail -2
|
|
||||||
204.78M clang
|
|
||||||
235.44M linux-firmware
|
|
||||||
```
|
|
||||||
|
|
||||||
### [pacman-list-disowned](/sh/pacman-list-disowned)
|
|
||||||
|
|
||||||
(zsh?) lists disowned pacman files. this might take a while.
|
|
||||||
[via prezto.][prezto]
|
|
||||||
|
|
||||||
### [pause](/sh/pause)
|
|
||||||
|
|
||||||
(bash/zsh) pause; the companion script of `confirm`.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ pause
|
|
||||||
Press any key to continue
|
|
||||||
$
|
|
||||||
```
|
|
||||||
|
|
||||||
### [pre](/sh/pre)
|
|
||||||
|
|
||||||
(bash/zsh) dumps all the #defines that `$CC $CPPFLAGS $CFLAGS $LDFLAGS` would result in.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ pre | shuf | head -10
|
|
||||||
#define __NO_MATH_INLINES 1
|
|
||||||
#define __FLT_MIN_10_EXP__ (-37)
|
|
||||||
#define __INT_LEAST32_TYPE__ int
|
|
||||||
#define __FLT_MIN_EXP__ (-125)
|
|
||||||
#define __LDBL_MIN_EXP__ (-16381)
|
|
||||||
#define __UINT8_C_SUFFIX__
|
|
||||||
#define __WINT_UNSIGNED__ 1
|
|
||||||
#define __INT_LEAST16_FMTd__ "hd"
|
|
||||||
#define __UINT_FAST32_MAX__ 4294967295U
|
|
||||||
#define __SSE__ 1
|
|
||||||
```
|
|
||||||
|
|
||||||
### [psbm](/sh/psbm)
|
|
||||||
|
|
||||||
(sh) lists processes by their memory usage, and the sum, ascending.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ psbm | head -n -1 | tail -2
|
|
||||||
185.08M 1163 chromium
|
|
||||||
199.95M 1060 chromium
|
|
||||||
```
|
|
||||||
|
|
||||||
### [randir](/sh/randir)
|
|
||||||
|
|
||||||
(sh) outputs a random directory in the working directory.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ randir
|
|
||||||
./sh
|
|
||||||
```
|
|
||||||
|
|
||||||
### [rs](/sh/rs)
|
|
||||||
|
|
||||||
(zsh) record screen. does not record audio.
|
|
||||||
|
|
||||||
currently only works on Windows (gdigrab).
|
|
||||||
i'm sure there's something equivalent for Linux.
|
|
||||||
|
|
||||||
### [sc](/sh/sc)
|
|
||||||
|
|
||||||
(bash) uploads given files to a webserver and returns a direct link for sharing.
|
|
||||||
you'll want to tweak this if you use it yourself.
|
|
||||||
|
|
||||||
has some extra logic for screenshots created by `scropt`.
|
|
||||||
|
|
||||||
### [scramble](/sh/sc)
|
|
||||||
|
|
||||||
(bash) scrambles text in a predictable way using regex.
|
|
||||||
|
|
||||||
(bhas) sacbremls ttex in a pdrceailtbe way unsig reegx.
|
|
||||||
|
|
||||||
### [screeny](/sh/screeny) + [unscreen](/sh/unscreen)
|
|
||||||
|
|
||||||
(zsh) sets up and detaches a screen for running daemons as other users, etc.
|
|
||||||
|
|
||||||
this will close any existing screens of the same name using its companion script, unscreen.
|
|
||||||
|
|
||||||
e.g. run znc as user znc in a screen called znc: `screeny znc znc znc -f`. znc!
|
|
||||||
|
|
||||||
<!--(you should really just use tmux though)-->
|
|
||||||
|
|
||||||
### [scropt](/sh/scropt)
|
|
||||||
|
|
||||||
(bash) runs `scrot` through `optipng` and saves to `~/play/$(now).png`.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ ~/sh/sc $(~/sh/scropt -s -d0.5)
|
|
||||||
```
|
|
||||||
|
|
||||||
### [similar](/sh/similar)
|
|
||||||
|
|
||||||
(sh) highlights similarities between adjacent lines.
|
|
||||||
|
|
||||||
### [slit](/sh/slit) + [slitt](/sh/slitt)
|
|
||||||
|
|
||||||
(zsh) views specific columns of text.
|
|
||||||
[via pretzo.][prezto]
|
|
||||||
|
|
||||||
```
|
|
||||||
$ df | slit 1 5
|
|
||||||
Filesystem Use%
|
|
||||||
dev 0%
|
|
||||||
run 1%
|
|
||||||
/dev/sda6 30%
|
|
||||||
tmpfs 3%
|
|
||||||
tmpfs 0%
|
|
||||||
tmpfs 1%
|
|
||||||
tmpfs 1%
|
|
||||||
```
|
|
||||||
|
|
||||||
`slitt` is exactly the same, but it works with tabs instead of spaces.
|
|
||||||
|
|
||||||
### [sram](/sh/sram)
|
|
||||||
|
|
||||||
(zsh) converts between a couple saveram formats for N64 emulators.
|
|
||||||
|
|
||||||
### [sv](/sh/sv)
|
|
||||||
|
|
||||||
(bash) collects the lastmost value of every key.
|
|
||||||
takes the field separator as an argument.
|
|
||||||
|
|
||||||
```
|
|
||||||
echo "this=that\nthem=those\nthis=cat" | sv =
|
|
||||||
this=cat
|
|
||||||
them=those
|
|
||||||
```
|
|
||||||
|
|
||||||
### [tpad](/sh/tpad)
|
|
||||||
|
|
||||||
(bash) adds a 1px transparent border around an image
|
|
||||||
so that twitter doesn't mangle it into a jpg.
|
|
||||||
sadly, this trick doesn't work anymore.
|
|
||||||
|
|
||||||
### [trunc](/sh/trunc)
|
|
||||||
|
|
||||||
(bash) truncates text to fit within your terminal using the unicode character `…`.
|
|
||||||
|
|
102
home/-shrc
102
home/-shrc
|
@ -1,27 +1,26 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
# for zsh, bash, and ash.
|
# for zsh, bash, and dash.
|
||||||
[ -n "$ZSH_VERSION" -o -n "$BASH" ] && FANCY=1 || FANCY=0
|
[ -n "$ZSH_VERSION" -o -n "$BASH" ] && FANCY=1 || FANCY=0
|
||||||
|
|
||||||
# {{{1 utilities
|
# {{{1 utilities
|
||||||
|
|
||||||
ify() {
|
#SOURCING=$((SOURCING+1))
|
||||||
[ $# -ge 2 ] || return
|
#. ~/sh/ify
|
||||||
local ex=$1
|
#. ~/sh/has
|
||||||
shift
|
#. ~/sh/maybesudo
|
||||||
$@ | $ex
|
#SOURCING=$((SOURCING-1))
|
||||||
}
|
|
||||||
|
|
||||||
if which sudo >/dev/null 2>/dev/null; then
|
# not available in busybox:
|
||||||
|
#exports() {
|
||||||
|
# printenv | cut -d= -f1
|
||||||
|
#}
|
||||||
|
|
||||||
|
if has sudo >/dev/null; then
|
||||||
alias maybesudo=sudo
|
alias maybesudo=sudo
|
||||||
else
|
else
|
||||||
maybesudo() {
|
alias maybesudo="maybesudo_ " # allows aliases within the alias
|
||||||
while [[ "$1" == -* ]]; do shift; done
|
|
||||||
"$@"
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
has() { which "$1" >&/dev/null && which "$1"; }
|
|
||||||
|
|
||||||
ADDPATH() {
|
ADDPATH() {
|
||||||
new="$(readlink -f "$1")"
|
new="$(readlink -f "$1")"
|
||||||
if [ ! -d "$new" ]; then
|
if [ ! -d "$new" ]; then
|
||||||
|
@ -54,10 +53,12 @@ umask 022
|
||||||
|
|
||||||
ADDPATH "$HOME/opt/local/bin"
|
ADDPATH "$HOME/opt/local/bin"
|
||||||
[ -n "$MSYSTEM" ] && ADDPATH "/c/path"
|
[ -n "$MSYSTEM" ] && ADDPATH "/c/path"
|
||||||
[ -n "$MSYSTEM" ] && ADDPATH "/c/path/mpv-shinchiro" 2>/dev/null
|
|
||||||
[ -n "$MSYSTEM" ] && ADDPATH "/c/Program Files/7-Zip-Zstandard" 2>/dev/null
|
[ -n "$MSYSTEM" ] && ADDPATH "/c/Program Files/7-Zip-Zstandard" 2>/dev/null
|
||||||
[ -n "$MSYSTEM" ] && ADDPATH ~win"/Desktop/_programs/rakudo-2021.06/bin" 2>/dev/null
|
[ -n "$MSYSTEM" ] && ADDPATH ~win"/Desktop/_programs/rakudo-2021.06/bin" 2>/dev/null
|
||||||
|
|
||||||
|
# for dash:
|
||||||
|
export ENV="$HOME/.-shrc"
|
||||||
|
|
||||||
# https://bugs.launchpad.net/ubuntu/+source/openssh/+bug/1380084
|
# https://bugs.launchpad.net/ubuntu/+source/openssh/+bug/1380084
|
||||||
export SSH_AUTH_SOCK=0
|
export SSH_AUTH_SOCK=0
|
||||||
|
|
||||||
|
@ -130,13 +131,11 @@ alias gb='git --no-pager branch'
|
||||||
# being specific {{{2
|
# being specific {{{2
|
||||||
|
|
||||||
[ -e "$HOME/python3" ] && alias py="~/python3" || alias py="python3"
|
[ -e "$HOME/python3" ] && alias py="~/python3" || alias py="python3"
|
||||||
alias maybesudo="maybesudo " # allows aliases within the alias
|
|
||||||
alias pip="maybesudo -H pip3"
|
alias pip="maybesudo -H pip3"
|
||||||
alias revend='objcopy -I binary -O binary --reverse-bytes=4'
|
alias revend='objcopy -I binary -O binary --reverse-bytes=4'
|
||||||
alias aur="BUILDDIR=$HOME/src $HOME/sh/aur -jj"
|
alias aur="BUILDDIR=$HOME/src $HOME/sh/aur -jj"
|
||||||
alias clone='maybesudo rsync -aHA --info=progress2 --no-i-r'
|
alias clone='maybesudo rsync -aHA --info=progress2 --no-i-r'
|
||||||
alias aligntabs="column -t -s$'\t'"
|
alias aligntabs="column -t -s$'\t'"
|
||||||
alias pippy="maybesudo py -m pip install --upgrade --upgrade-strategy only-if-needed"
|
|
||||||
alias crawla='ssh joshua@crawl.akrasiac.org -i ~/.ssh/crawl'
|
alias crawla='ssh joshua@crawl.akrasiac.org -i ~/.ssh/crawl'
|
||||||
alias crawlz='ssh crawl@crawl.develz.org -i ~/.ssh/crawl'
|
alias crawlz='ssh crawl@crawl.develz.org -i ~/.ssh/crawl'
|
||||||
|
|
||||||
|
@ -165,78 +164,13 @@ alias join2='paste -d" " - -'
|
||||||
alias katagana='perlu -MUnicode::Normalize -pe'"'"'$_=NFKD($_)=~y/ァ-ヶ /ぁ-ゖ /r'"'"
|
alias katagana='perlu -MUnicode::Normalize -pe'"'"'$_=NFKD($_)=~y/ァ-ヶ /ぁ-ゖ /r'"'"
|
||||||
alias picky='{ pacman -Qgq base base-devel xorg xorg-drivers xfce4 | double; pacman -Qeq; } | sort | uniq -u'
|
alias picky='{ pacman -Qgq base base-devel xorg xorg-drivers xfce4 | double; pacman -Qeq; } | sort | uniq -u'
|
||||||
alias unused='{ pacman -Qtq; pacman -Qeq | double; } | sort | uniq -u'
|
alias unused='{ pacman -Qtq; pacman -Qeq | double; } | sort | uniq -u'
|
||||||
alias makepkgf='maybesudo -u $USER makepkg -Af --skipchecksums --skippgpcheck'
|
alias makepkgf='makepkg -Af --skipchecksums --skippgpcheck'
|
||||||
alias rakef='rake && gem build *.gemspec && gem install *.gem'
|
alias rakef='rake && gem build *.gemspec && gem install *.gem'
|
||||||
|
|
||||||
trash() {
|
|
||||||
dd status=none if=/dev/random bs=1 count="$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
explore() {
|
|
||||||
explorer "$(cygpath -w "${1:-.}")"
|
|
||||||
}
|
|
||||||
|
|
||||||
pegg() {
|
|
||||||
pippy "https://github.com/$1/$2/tarball/${3:-master}#egg=$2"
|
|
||||||
}
|
|
||||||
|
|
||||||
bak() {
|
|
||||||
if [ -s "$1.bak" ]; then
|
|
||||||
bak "$1.bak" || return $?
|
|
||||||
fi
|
|
||||||
cp -p "$1" "$1.bak"
|
|
||||||
}
|
|
||||||
|
|
||||||
baks() { # backup, timestamped
|
|
||||||
local fp="$1"
|
|
||||||
local now="$(date -u '+%y-%m-%d_%H-%M-%S')"
|
|
||||||
local bak="$fp.$now.bak"
|
|
||||||
if [ -s "$bak" ]; then
|
|
||||||
printf "how in the hell? %s already exists\n" "$bak" >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
cp -p "$fp" "$bak"
|
|
||||||
}
|
|
||||||
|
|
||||||
eashare() {
|
eashare() {
|
||||||
# NOTE: this only works on MSYS2 for now.
|
# NOTE: this only works on MSYS2 for now.
|
||||||
# NOTE: i lied, this doesn't work anymore. idk
|
# NOTE: i lied, this doesn't work anymore. idk
|
||||||
local dest="${1##*/}"
|
local dest="${1##*/}"
|
||||||
eaput "$1" || return 1
|
eaput "$1" || return 1
|
||||||
printf "%s" "$_REMOTE_DOMAIN/$_REMOTE_DIR/$dest" > /dev/clipboard
|
printf "%s" "$_REMOTE_DOMAIN/$_REMOTE_DIR/$dest" >> /dev/clipboard
|
||||||
}
|
}
|
||||||
|
|
||||||
echo2() {
|
|
||||||
local IFS=" "
|
|
||||||
printf "%s\n" "$*" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
note() {
|
|
||||||
local IFS=" "
|
|
||||||
printf "\033[1m%s\033[0m\n" "$*" >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
stfu() {
|
|
||||||
local ret=0
|
|
||||||
"$@" > .stdout 2> .stderr || ret=$?
|
|
||||||
if test "$ret" -ne 0; then
|
|
||||||
printf "command failed with exit status %s:\n" "$ret" >&2
|
|
||||||
echo2 "$@"
|
|
||||||
echo2
|
|
||||||
note '$ tail -n 20 .stdout'
|
|
||||||
tail -n 20 .stdout >&2
|
|
||||||
echo2
|
|
||||||
note '$ tail -n 20 .stderr'
|
|
||||||
tail -n 20 .stderr >&2
|
|
||||||
return "$ret"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# sources {{{1
|
|
||||||
|
|
||||||
if [ $FANCY -eq 1 ]; then
|
|
||||||
source ~/.arrays
|
|
||||||
source ~/.streamcrap
|
|
||||||
fi
|
|
||||||
|
|
||||||
. ~/.ea
|
|
||||||
|
|
28
home/bashrc
28
home/bashrc
|
@ -1,6 +1,16 @@
|
||||||
[ -z "$PS1" ] && return
|
[ -z "$PS1" ] && return
|
||||||
|
echo START.bashrc
|
||||||
|
|
||||||
if [[ "$TERM" == "rxvt-unicode-256color" ]]; then
|
# trace: (on ubuntu)
|
||||||
|
# /etc/bash.bashrc
|
||||||
|
#=> /etc/debian_chroot
|
||||||
|
#=> /.sudo_as_admin_successful
|
||||||
|
#=> /.hushlogin
|
||||||
|
#=> /usr/lib/command-not-found
|
||||||
|
#=> /usr/share/command-not-found/command-not-found
|
||||||
|
# ~/.bashrc
|
||||||
|
|
||||||
|
if [ "$TERM" = rxvt-unicode-256color ]; then
|
||||||
export TERM=xterm-256color
|
export TERM=xterm-256color
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -28,9 +38,25 @@ ret_fail="$_title${Cfail}$_line1\n${Cfail}$_line2"
|
||||||
|
|
||||||
PROMPT_COMMAND='[ $? = 0 ] && PS1=${ret_succ} || PS1=${ret_fail}'
|
PROMPT_COMMAND='[ $? = 0 ] && PS1=${ret_succ} || PS1=${ret_fail}'
|
||||||
|
|
||||||
|
SOURCING=$((SOURCING+1))
|
||||||
|
. ~/sh/echo2
|
||||||
|
. ~/sh/note
|
||||||
|
. ~/sh/stfu
|
||||||
|
. ~/sh/has
|
||||||
|
SOURCING=$((SOURCING-1))
|
||||||
|
|
||||||
|
echo START.-shrc
|
||||||
. ~/.-shrc
|
. ~/.-shrc
|
||||||
|
echo FINISH.-shrc
|
||||||
|
|
||||||
|
SOURCING=$((SOURCING+1))
|
||||||
|
. ~/sh/arrays
|
||||||
|
. ~/sh/streamcrap
|
||||||
|
SOURCING=$((SOURCING-1))
|
||||||
|
|
||||||
# this doesn't work for all scripts at the moment, but
|
# this doesn't work for all scripts at the moment, but
|
||||||
ADDPATH "$HOME/sh"
|
ADDPATH "$HOME/sh"
|
||||||
|
|
||||||
|
# TODO: respect initctl like in .zshrc.
|
||||||
alias reload='cd; exec bash'
|
alias reload='cd; exec bash'
|
||||||
|
echo FINISH.bashrc
|
||||||
|
|
|
@ -1,16 +1,6 @@
|
||||||
# this code comes from prezto:
|
# this code comes from prezto:
|
||||||
# https://github.com/sorin-ionescu/prezto/blob/master/modules/completion/init.zsh
|
# https://github.com/sorin-ionescu/prezto/blob/master/modules/completion/init.zsh
|
||||||
|
|
||||||
setopt COMPLETE_IN_WORD # Complete from both ends of a word.
|
|
||||||
setopt ALWAYS_TO_END # Move cursor to the end of a completed word.
|
|
||||||
setopt PATH_DIRS # Perform path search even on command names with slashes.
|
|
||||||
setopt AUTO_MENU # Show completion menu on a successive tab press.
|
|
||||||
setopt AUTO_LIST # Automatically list choices on ambiguous completion.
|
|
||||||
setopt AUTO_PARAM_SLASH # If completed parameter is a directory, add a trailing slash.
|
|
||||||
setopt EXTENDED_GLOB # Needed for file modification glob modifiers with compinit
|
|
||||||
unsetopt MENU_COMPLETE # Do not autoselect the first completion entry.
|
|
||||||
unsetopt FLOW_CONTROL # Disable start/stop characters in shell editor.
|
|
||||||
|
|
||||||
# Load and initialize the completion system ignoring insecure directories with a
|
# Load and initialize the completion system ignoring insecure directories with a
|
||||||
# cache time of 20 hours, so it should almost always regenerate the first time a
|
# cache time of 20 hours, so it should almost always regenerate the first time a
|
||||||
# shell is opened each day.
|
# shell is opened each day.
|
||||||
|
|
223
home/zshrc
223
home/zshrc
|
@ -1,61 +1,84 @@
|
||||||
|
echo START.PROFILE
|
||||||
[ -e /etc/profile ] && emulate sh -c "source /etc/profile"
|
[ -e /etc/profile ] && emulate sh -c "source /etc/profile"
|
||||||
|
echo FINISH.PROFILE
|
||||||
|
|
||||||
if [ "$SHLVL" -le 1 ] && [[ "$TERM" != screen* ]] && [[ "$TERM" != tmux* ]]
|
# trace:
|
||||||
then
|
# /etc/zsh/zshenv{.zwc,}
|
||||||
if which tmux >/dev/null 2>/dev/null; then
|
# ~/.zshenv{.zwc,}
|
||||||
# create a new session called "what" or attach if it already exists
|
# /etc/zsh/zshrc{.zwc,}
|
||||||
LANG="en_US.UTF-8" TZ=":/etc/localtime" tmux new -A -s what && exit
|
|
||||||
echo "tmux died ($?), continuing..."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
setopt extended_glob # required for various scripts in this file and otherwise
|
|
||||||
|
|
||||||
local host="${(L)HOST}"
|
|
||||||
fpath=(~/sh $fpath)
|
|
||||||
|
|
||||||
function {
|
|
||||||
local f
|
|
||||||
for f in ~/sh/^([_.]*)(N^/:t); do
|
|
||||||
if [[ "$f" == fasd ]]; then
|
|
||||||
emulate sh -c "autoload -U $f"
|
|
||||||
else
|
|
||||||
autoload -Uz $f
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
HISTFILE=~/.histfile
|
HISTFILE=~/.histfile
|
||||||
HISTSIZE=99999
|
HISTSIZE=99999
|
||||||
SAVEHIST=99999
|
SAVEHIST=99999
|
||||||
|
TIMEFMT=$'\e[93m%*U/%*E cpu/real (%P), %MM mem:\e[36m %J\e[0m'
|
||||||
|
DIRSTACKSIZE=24
|
||||||
|
|
||||||
function {
|
setopt always_to_end # Move cursor to the end of a completed word.
|
||||||
local -a opts
|
setopt append_history
|
||||||
opts=( no_beep
|
setopt share_history # across sessions
|
||||||
append_history share_history # across sessions
|
setopt auto_cd # exec a dir to cd
|
||||||
hist_expire_dups_first # sharing/appending will result in dups
|
setopt auto_list # Automatically list choices on ambiguous completion.
|
||||||
hist_ignore_dups # don't push lines identical to the previous
|
setopt auto_menu # Show completion menu on a successive tab press.
|
||||||
hist_ignore_space # don't push lines beginning with spaces
|
setopt auto_param_slash # If completed parameter is a directory, add a trailing slash.
|
||||||
auto_cd # exec a dir to cd
|
setopt auto_pushd # cd acts as pushd
|
||||||
auto_pushd # cd acts as pushd
|
setopt brace_ccl # for character ranges like {a-z}
|
||||||
no_match # error on bad tab-complete
|
setopt chase_links # cd into link resolves link
|
||||||
check_jobs notify # automatic job reporting
|
setopt check_jobs notify # automatic job reporting
|
||||||
chase_links # cd into link resolves link
|
setopt complete_aliases # allow original command completion within alias
|
||||||
complete_aliases # allow original command completion within alias
|
setopt complete_in_word # enable tab completion from any characters in a word
|
||||||
complete_in_word # enable tab completion when cursor between words
|
setopt extended_glob # required for various scripts in this file and otherwise
|
||||||
rc_quotes # 'you''re dumb' like "you're dumb"
|
setopt hist_expire_dups_first # sharing/appending will result in dups
|
||||||
brace_ccl # for character ranges like {a-z}
|
setopt hist_ignore_dups # don't push lines identical to the previous
|
||||||
ksh_typeset # treat `local x=$(cmd)` and `x=$(cmd)` the same
|
setopt hist_ignore_space # don't push lines beginning with spaces
|
||||||
)
|
setopt ksh_typeset # treat `local x=$(cmd)` and `local x="$(cmd)"` the same
|
||||||
setopt "${opts[@]}"
|
setopt no_beep
|
||||||
}
|
setopt no_match # error on bad tab-complete
|
||||||
|
setopt path_dirs # Perform path search even on command names with slashes.
|
||||||
|
setopt rc_quotes # 'it''s okay' becomes "it's okay"
|
||||||
|
unsetopt flow_control # Disable start/stop characters in shell editor.
|
||||||
|
unsetopt menu_complete # Do not autoselect the first completion entry.
|
||||||
|
|
||||||
|
if [ "$SHLVL" -le 1 ] && [ "$TERM" = "${TERM#screen}" ] && [ "$TERM" = "${TERM#tmux}" ]; then
|
||||||
|
if (( $+commands[tmux] )); then
|
||||||
|
# create a new session called "what" or attach if it already exists
|
||||||
|
LANG="en_US.UTF-8" TZ=":/etc/localtime" tmux new -A -s what && exit
|
||||||
|
printf '\e[91m\ntmux died (%i), continuing...\n\e[0m\n' $?
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
autoload -U zmv
|
autoload -U zmv
|
||||||
|
autoload -U zrecompile
|
||||||
zmodload zsh/mathfunc
|
|
||||||
autoload -Uz zcalc
|
autoload -Uz zcalc
|
||||||
|
autoload edit-command-line
|
||||||
|
autoload history-search-end
|
||||||
|
zmodload zsh/mathfunc
|
||||||
|
|
||||||
|
echo START.SH
|
||||||
|
|
||||||
|
function {
|
||||||
|
local a b
|
||||||
|
|
||||||
|
[ -s ~/.sh.sha1 ] && read -r b < ~/.sh.sha1
|
||||||
|
( cd ~/sh \
|
||||||
|
&& print -l '#!/usr/bin/env false' '[ "${SOURCING:-0}" -gt 0 ] || exit 1' '' \
|
||||||
|
| cat - $(grep -lF 'YES_ZSH' *(.)) \
|
||||||
|
| tee ~/.sh \
|
||||||
|
) | sha1sum - \
|
||||||
|
| cut -d' ' -f1 \
|
||||||
|
| tee ~/.sh.sha1 \
|
||||||
|
| read -r a
|
||||||
|
|
||||||
|
[ "$a" = "$b" ] && touch ~/.sh.zwc || zrecompile -p ~/.sh
|
||||||
|
}
|
||||||
|
|
||||||
|
SOURCING=$((SOURCING+1))
|
||||||
|
. ~/.sh
|
||||||
|
SOURCING=$((SOURCING-1))
|
||||||
|
|
||||||
|
echo FINISH.SH
|
||||||
|
|
||||||
|
local fuzzy=`has fzy || print`
|
||||||
|
|
||||||
DIRSTACKSIZE=24
|
|
||||||
dirprev() {
|
dirprev() {
|
||||||
pushd -q +1
|
pushd -q +1
|
||||||
zle reset-prompt
|
zle reset-prompt
|
||||||
|
@ -72,11 +95,17 @@ dirup() {
|
||||||
precmd
|
precmd
|
||||||
}
|
}
|
||||||
dirview() {
|
dirview() {
|
||||||
# TODO: print under prompt if possible,
|
|
||||||
# truncate and columnize
|
|
||||||
print
|
print
|
||||||
dirs -v
|
if [ -n "$fuzzy" ]; then
|
||||||
|
local d="$(dirs -pl | awk '!seen[$0]++' | "$fuzzy")"
|
||||||
|
cd "$d"
|
||||||
|
else
|
||||||
|
# TODO: print under prompt if possible,
|
||||||
|
# truncate and columnize
|
||||||
|
dirs -v
|
||||||
|
fi
|
||||||
zle reset-prompt
|
zle reset-prompt
|
||||||
|
precmd
|
||||||
}
|
}
|
||||||
|
|
||||||
for x (dirprev dirnext dirup dirview) zle -N $x
|
for x (dirprev dirnext dirup dirview) zle -N $x
|
||||||
|
@ -84,7 +113,6 @@ for x (dirprev dirnext dirup dirview) zle -N $x
|
||||||
bindkey -e # emacs-style keybinds
|
bindkey -e # emacs-style keybinds
|
||||||
|
|
||||||
# oh thank god: http://blog.samsonis.me/2013/12/bash-like-history-search-functionality-for-zsh/
|
# oh thank god: http://blog.samsonis.me/2013/12/bash-like-history-search-functionality-for-zsh/
|
||||||
autoload history-search-end
|
|
||||||
zle -N history-beginning-search-backward-end history-search-end
|
zle -N history-beginning-search-backward-end history-search-end
|
||||||
zle -N history-beginning-search-forward-end history-search-end
|
zle -N history-beginning-search-forward-end history-search-end
|
||||||
bindkey '^[[A' history-beginning-search-backward-end # up
|
bindkey '^[[A' history-beginning-search-backward-end # up
|
||||||
|
@ -133,39 +161,26 @@ bindkey -s '^[[6;2~' '\a' # shift+PgDn, do nothing, already at bottom (tmux)
|
||||||
#bindkey -s '^[[1;8C' '\a' # ctrl+alt+shift+arrow
|
#bindkey -s '^[[1;8C' '\a' # ctrl+alt+shift+arrow
|
||||||
#bindkey -s '^[[1;8D' '\a' # ctrl+alt+shift+arrow
|
#bindkey -s '^[[1;8D' '\a' # ctrl+alt+shift+arrow
|
||||||
|
|
||||||
autoload edit-command-line
|
|
||||||
zle -N edit-command-line # new widget of the same function name
|
zle -N edit-command-line # new widget of the same function name
|
||||||
bindkey '^Xe' edit-command-line # ctrl+x -> e
|
bindkey '^Xe' edit-command-line # ctrl+x -> e
|
||||||
|
|
||||||
|
echo START.-
|
||||||
. ~/.-shrc
|
. ~/.-shrc
|
||||||
|
echo FINISH.-
|
||||||
|
|
||||||
alias -g OMFG="1>/dev/null"
|
alias -g OMFG="1>/dev/null"
|
||||||
alias -g STFU="2>/dev/null"
|
alias -g STFU="2>/dev/null"
|
||||||
alias -g WHOA='${whoa[@]}'
|
alias -g WHOA='${whoa[@]}'
|
||||||
alias -g WELP='${welp[@]}'
|
alias -g WELP='${welp[@]}'
|
||||||
|
|
||||||
wipe() {
|
|
||||||
clear
|
|
||||||
clear # twice because mintty is weird
|
|
||||||
echo "\e[30m\e[107m"
|
|
||||||
printf "*%.0s" {1..$COLUMNS}
|
|
||||||
echo "\e[0m\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
alias sc="~/sh/sc" # only runs in bash (for now), so be explicit with path
|
alias sc="~/sh/sc" # only runs in bash (for now), so be explicit with path
|
||||||
alias pl="print -l" # not in -shrc because this only makes sense with zsh
|
alias pl="print -l" # not in -shrc because this only makes sense with zsh
|
||||||
|
|
||||||
function tw() { # needs the "function" keyword or else zsh complains
|
function tw() { # needs the "function" keyword or else zsh complains
|
||||||
twitch "$@" OMFG STFU &
|
twitch "$@" OMFG STFU &
|
||||||
}
|
}
|
||||||
|
|
||||||
sum() {
|
local host="${(L)HOST}"
|
||||||
local sum=0
|
|
||||||
for i; do
|
|
||||||
sum=$((sum+i))
|
|
||||||
done
|
|
||||||
echo "$sum"
|
|
||||||
}
|
|
||||||
|
|
||||||
function {
|
function {
|
||||||
local t="${TERM%%-*}"
|
local t="${TERM%%-*}"
|
||||||
|
@ -193,67 +208,37 @@ function {
|
||||||
local good=42 # green
|
local good=42 # green
|
||||||
local bad=41 # red
|
local bad=41 # red
|
||||||
|
|
||||||
[[ "$host" == neobanshee ]] && good=46 # cyan
|
[ "$host" = neobanshee ] && good=46 # cyan
|
||||||
[[ "$host" == spectre ]] && good=47 # white
|
[ "$host" = spectre ] && good=47 # white
|
||||||
[[ "$host" == wraith ]] && good=43 # yellow
|
[ "$host" = wraith ] && good=43 # yellow
|
||||||
[[ "$host" == sabotage ]] && good=45 # magenta
|
[ "$host" = sabotage ] && good=45 # magenta
|
||||||
|
|
||||||
# NOTE: i had ${s}10${e} here before, is it still necessary?
|
# NOTE: i had ${s}10${e} here before, is it still necessary?
|
||||||
PROMPT="%{$reset${s}%(?.${good}.${bad})${e}${s}97${e}%}%#%{$reset%} "
|
PROMPT="%{$reset${s}%(?.${good}.${bad})${e}${s}97${e}%}%#%{$reset%} "
|
||||||
}
|
}
|
||||||
|
|
||||||
TIMEFMT=$'\e[93m%*U/%*E cpu/real (%P), %MM mem:\e[36m %J\e[0m'
|
|
||||||
|
|
||||||
reload() {
|
reload() {
|
||||||
|
# initctl has a "reload" symlink, but i'm already too used to typing this.
|
||||||
|
# to remedy this, when args are passed, invoke initctl instead.
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
"${commands[reload]:?initctl is missing}" "$@"
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
|
||||||
# this doesn't seem to help with _vim_files errors, eh.
|
# this doesn't seem to help with _vim_files errors, eh.
|
||||||
# you wanna rm .zcompdump first, then exit. that's why!
|
# you wanna rm .zcompdump first, then exit. that's why!
|
||||||
cd ~
|
cd ~
|
||||||
autoload -U zrecompile
|
if [ $? -eq 0 ]; then
|
||||||
[ -f .zshrc ] && zrecompile -p .zshrc
|
[ -f .zshrc ] && zrecompile -p .zshrc
|
||||||
rm -f .zcompdump
|
[ -f .prezto-compinit ] && zrecompile -p .prezto-compinit
|
||||||
[ -f .zshrc.zwc.old ] && rm -f .zshrc.zwc.old
|
rm -f .zcompdump .zshrc.zwc.old .zcompdump.zwc.old
|
||||||
[ -f .zcompdump.zwc.old ] && rm -f .zcompdump.zwc.old
|
fi
|
||||||
exec zsh # reload shell, inheriting environment
|
exec zsh # reload shell, inheriting environment
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ "$host" == "spectre" ]] || [[ "$host" == *"banshee" ]]; then
|
#zmodload zsh/complist # need all this
|
||||||
# via https://github.com/whjvenyl/fasd
|
#autoload -Uz compinit && compinit # just for compdef
|
||||||
# if [ ! -s "$HOME/.fasd_init" ]; then
|
#compdef wat=which
|
||||||
# # note that posix-alias defines aliases for the following:
|
|
||||||
# # a s d f sd sf z zz
|
|
||||||
# fasd --init \
|
|
||||||
# posix-alias \
|
|
||||||
# zsh-hook zsh-ccomp zsh-ccomp-install \
|
|
||||||
# zsh-wcomp zsh-wcomp-install \
|
|
||||||
# >| "$HOME/.fasd_init"
|
|
||||||
# fi
|
|
||||||
# source "$HOME/.fasd_init"
|
|
||||||
# alias v="f -e $EDITOR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
baknow() { cp -ip "$1" "$1.$(now "$1").bak"; }
|
|
||||||
|
|
||||||
ff() { find "${1:-.}" -type f | fzy }
|
|
||||||
|
|
||||||
cutv() {
|
|
||||||
local nel="${1?missing length parameter}"
|
|
||||||
local f="${2?missing file parameter}"
|
|
||||||
local g="cut."${${f##*/}%.*}".mp4"
|
|
||||||
ffmpeg -hide_banner -i "$f" 2>&1 \
|
|
||||||
| grep Duration \
|
|
||||||
| grep -Eo '[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9]' | awk -F: '{print (($1*60+$2)*60+$3)+$4/100}' | read len
|
|
||||||
[[ "$len" -gt 0 ]] || return 1
|
|
||||||
echo "$g"
|
|
||||||
ffmpeg \
|
|
||||||
-hide_banner -loglevel warning -stats -stats_period 5 \
|
|
||||||
-i "$f" -ss "$(((nel<len)*(len-nel)))" \
|
|
||||||
-sn -dn -metadata = -map_chapters -1 -movflags +faststart \
|
|
||||||
-ar 44100 -acodec libfdk_aac -b:a 256k -cutoff 20000 -af alimiter=level_in=2.5:level_out=0.9 \
|
|
||||||
-maxrate 7680k -bufsize 9600k -vcodec libx264 -preset medium -crf 21 -vf scale=1280:720 \
|
|
||||||
-threads 2 -y "$g" || return 1
|
|
||||||
# -maxrate 7680k -bufsize 9600k -vcodec libx264 -preset medium -crf 21 -vf scale=1280:720
|
|
||||||
# -maxrate 9600k -bufsize 12000k -vcodec libx264 -preset medium -crf 22 -vf scale=1280:720
|
|
||||||
}
|
|
||||||
|
|
||||||
# generated by dircolors with https://github.com/isene/LS_COLORS
|
# generated by dircolors with https://github.com/isene/LS_COLORS
|
||||||
function {
|
function {
|
||||||
|
@ -270,4 +255,6 @@ for x in ai arith curl fc find ftp hex history let locate rsync scp sftp tw twit
|
||||||
alias $x="noglob $x"
|
alias $x="noglob $x"
|
||||||
unset x
|
unset x
|
||||||
|
|
||||||
source ~/.prezto-compinit
|
echo START.COMPINIT
|
||||||
|
. ~/.prezto-compinit
|
||||||
|
echo FINISH.COMPINIT
|
||||||
|
|
4
install
4
install
|
@ -135,8 +135,8 @@ cd "$HOME" || exit 1
|
||||||
|
|
||||||
backup_dir="$rc/backup-$(date -u '+%s')"
|
backup_dir="$rc/backup-$(date -u '+%s')"
|
||||||
|
|
||||||
for f in .bashrc .zshrc .-shrc .arrays .prezto-compinit .ls_colors \
|
for f in .bashrc .zshrc .-shrc .prezto-compinit .ls_colors \
|
||||||
.streamcrap .ea .vimrc .inputrc .Xresources .screenrc .tmux.conf; do
|
.vimrc .inputrc .Xresources .screenrc .tmux.conf; do
|
||||||
dotless "$f"
|
dotless "$f"
|
||||||
r="$rc/home/$REPLY"
|
r="$rc/home/$REPLY"
|
||||||
hardlink "$f" "$r"
|
hardlink "$f" "$r"
|
||||||
|
|
8
sh/arith
8
sh/arith
|
@ -1,2 +1,8 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
<<<"$(($@))"
|
# YES_ZSH
|
||||||
|
|
||||||
|
arith() {
|
||||||
|
<<<"$(($@))"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || arith "$@"
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
#!/usr/bin/env false
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
whoa=(
|
whoa=(
|
||||||
-Wall
|
-Wall
|
||||||
-Wextra
|
-Wextra
|
5
sh/aur
5
sh/aur
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# http://aur.sh with massive feature creep
|
# http://aur.sh with massive feature creep
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
aur() {
|
aur() {
|
||||||
trap 'exit 1' SIGINT SIGTERM
|
trap 'exit 1' SIGINT SIGTERM
|
||||||
|
|
||||||
|
@ -124,4 +126,5 @@ aur() {
|
||||||
|
|
||||||
[ "$fail" -eq 0 ] && return 0 || return 1
|
[ "$fail" -eq 0 ] && return 0 || return 1
|
||||||
}
|
}
|
||||||
aur "$@"
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || aur "$@"
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
autosync() {
|
autosync() {
|
||||||
target="$1"
|
target="$1"
|
||||||
shift
|
shift
|
||||||
|
@ -8,4 +10,5 @@ autosync() {
|
||||||
\rsync -rtl "$@" "$target"
|
\rsync -rtl "$@" "$target"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
autosync "$@"
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || autosync "$@"
|
||||||
|
|
16
sh/bak
Normal file
16
sh/bak
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
bak() {
|
||||||
|
[ $# -gt 0 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; }
|
||||||
|
local ret=0
|
||||||
|
for f; do
|
||||||
|
if [ -s "$f.bak" ]; then
|
||||||
|
bak "$f.bak" || ret=1
|
||||||
|
fi
|
||||||
|
cp -p "$f" "$f.bak"
|
||||||
|
done
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || bak "$@"
|
8
sh/baknow
Normal file
8
sh/baknow
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
baknow() {
|
||||||
|
cp -ip "${1:?missing file argument}" "$1.$(now "$1").bak"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || baknow "$@"
|
22
sh/baks
Normal file
22
sh/baks
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
#SOURCING=$((SOURCING+1))
|
||||||
|
#. ~/sh/note # FIXME: don't do this?
|
||||||
|
#SOURCING=$((SOURCING-1))
|
||||||
|
|
||||||
|
baks() { # backup, timestamped
|
||||||
|
local ret=0
|
||||||
|
for fp; do
|
||||||
|
local now="$(date -u '+%y-%m-%d_%H-%M-%S')"
|
||||||
|
local bak="$fp.$now.bak"
|
||||||
|
if [ -s "$bak" ]; then
|
||||||
|
note "how in the hell?" "$bak" "already exists"
|
||||||
|
ret=1
|
||||||
|
fi
|
||||||
|
cp -p "$fp" "$bak" || ret=1
|
||||||
|
done
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || baks "$@"
|
10
sh/bin
Normal file
10
sh/bin
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/usr/bin/env zsh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
bin() {
|
||||||
|
local a="$(($@))"
|
||||||
|
let 'a=(((((((((((((a + 0x0FFFFF80) & 0x1000007F) + 0x00FFFFC0) & 0x1100003F) + 0x000FFFE0) & 0x1110001F) + 0x0000FFF0) & 0x1111000F) + 0x00000FF8) & 0x11111007) + 0x000000FC) & 0x11111103) + 0x0000000E) & 0x11111111'
|
||||||
|
printf "%08X\n" "$a"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || bin "$@"
|
14
sh/cdbusiest
14
sh/cdbusiest
|
@ -1,5 +1,11 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
dbusiest | read -r c d
|
# YES_ZSH
|
||||||
[ -z $c ] && return 1
|
|
||||||
<<<"$c $d"
|
cdbusiest() {
|
||||||
cd $d
|
dbusiest | read -r c d
|
||||||
|
[ -z $c ] && return 1
|
||||||
|
<<<"$c $d"
|
||||||
|
cd $d
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || cdbusiest "$@"
|
||||||
|
|
|
@ -1,2 +1,8 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
printf "\e[%dm$(printf " \e[%dm mV \e[40m" {4,10}{0..7})\e[0m\n" {3,9}{0..7}
|
# YES_ZSH
|
||||||
|
|
||||||
|
colors() {
|
||||||
|
printf "\e[%dm$(printf " \e[%dm mV \e[40m" {4,10}{0..7})\e[0m\n" {3,9}{0..7}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || colors "$@"
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/zsh
|
#!/usr/bin/zsh
|
||||||
|
# YES_ZSH
|
||||||
# script to make sense of compand's parameters
|
# script to make sense of compand's parameters
|
||||||
|
|
||||||
compandy() {
|
compandy() {
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
echo -E "usage: $0 {threshold} {ratio} [attack] [release] [knee] [gain] [delay]"
|
echo -E "usage: $0 {threshold} {ratio} [attack] [release] [knee] [gain] [delay]"
|
||||||
|
@ -17,4 +19,5 @@ compandy() {
|
||||||
printf "compand=%.5f|%.5f:%.5f|%.5f:%.1f/%.1f|0/%.2f:%.2f:%.2f:%.1f:%.5f" \
|
printf "compand=%.5f|%.5f:%.5f|%.5f:%.1f/%.1f|0/%.2f:%.2f:%.2f:%.1f:%.5f" \
|
||||||
$atk $atk $rel $rel $thresh $thresh $end $knee $gain $start $delay
|
$atk $atk $rel $rel $thresh $thresh $end $knee $gain $start $delay
|
||||||
}
|
}
|
||||||
compandy "$@"
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || compandy "$@"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
# I'll just leave this here...
|
# I'll just leave this here...
|
||||||
__setup_clang_ubuntu() {
|
__setup_clang_ubuntu() {
|
||||||
|
@ -298,4 +299,4 @@ compile() {
|
||||||
$compiler $std ${final_flags[@]} $file ${libraries[@]} ${warnings[@]} $outflag $out
|
$compiler $std ${final_flags[@]} $file ${libraries[@]} ${warnings[@]} $outflag $out
|
||||||
}
|
}
|
||||||
|
|
||||||
compile "$@"
|
[ "${SOURCING:-0}" -gt 0 ] || compile "$@"
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
if [ -n "${ZSH_VERSION:-}" ]; then
|
if [ -n "${ZSH_VERSION:-}" ]; then
|
||||||
confirm() {
|
confirm() {
|
||||||
|
[ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
read -q '?Continue? [y/N] '
|
read -q '?Continue? [y/N] '
|
||||||
ret=$?
|
ret=$?
|
||||||
echo
|
echo
|
||||||
|
@ -9,10 +12,12 @@ if [ -n "${ZSH_VERSION:-}" ]; then
|
||||||
else
|
else
|
||||||
confirm() {
|
confirm() {
|
||||||
# specify stdin (1) to avoid taking input from pipes
|
# specify stdin (1) to avoid taking input from pipes
|
||||||
|
[ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
read -n1 -u 1 -p "Continue? [y/N] " c
|
read -n1 -u 1 -p "Continue? [y/N] " c
|
||||||
echo
|
echo
|
||||||
[ "$c" != 'y' ] && [ "$c" != 'Y' ] && return 1
|
[ "$c" != 'y' ] && [ "$c" != 'Y' ] && return 1
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
confirm
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || confirm "$@"
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
countdiff() {
|
countdiff() {
|
||||||
|
[ $# -le 2 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
git --no-pager diff --stat --no-color --no-index "$1" "$2" \
|
git --no-pager diff --stat --no-color --no-index "$1" "$2" \
|
||||||
| awk '/changed/{print $4+$6;a=1}END{if(!a)print 0}'
|
| awk '/changed/{print $4+$6;a=1}END{if(!a)print 0}'
|
||||||
}
|
}
|
||||||
countdiff "$@"
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || countdiff "$@"
|
||||||
|
|
25
sh/cutv
Normal file
25
sh/cutv
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#!/usr/bin/env zsh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
cutv() {
|
||||||
|
[ $# -le 4 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
|
local nel="${1?missing length parameter}"
|
||||||
|
local f="${2?missing file parameter}"
|
||||||
|
local g="cut."${${f##*/}%.*}".mp4"
|
||||||
|
ffmpeg -hide_banner -i "$f" 2>&1 \
|
||||||
|
| grep Duration \
|
||||||
|
| grep -Eo '[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9]' | awk -F: '{print (($1*60+$2)*60+$3)+$4/100}' | read len
|
||||||
|
[[ "$len" -gt 0 ]] || return 1
|
||||||
|
echo "$g"
|
||||||
|
ffmpeg \
|
||||||
|
-hide_banner -loglevel warning -stats -stats_period 5 \
|
||||||
|
-i "$f" -ss "$(((nel<len)*(len-nel)))" \
|
||||||
|
-sn -dn -metadata = -map_chapters -1 -movflags +faststart \
|
||||||
|
-ar 44100 -acodec libfdk_aac -b:a 256k -cutoff 20000 -af alimiter=level_in=2.5:level_out=0.9 \
|
||||||
|
-maxrate 7680k -bufsize 9600k -vcodec libx264 -preset medium -crf 21 -vf scale=1280:720 \
|
||||||
|
-threads 2 -y "$g" || return 1
|
||||||
|
# -maxrate 7680k -bufsize 9600k -vcodec libx264 -preset medium -crf 21 -vf scale=1280:720
|
||||||
|
# -maxrate 9600k -bufsize 12000k -vcodec libx264 -preset medium -crf 22 -vf scale=1280:720
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || cutv "$@"
|
9
sh/days
9
sh/days
|
@ -1,2 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
echo $(( ($(date +%s) - $(date -d "$1" +%s)) / 60 / 60 / 24 ))
|
# YES_ZSH
|
||||||
|
|
||||||
|
days() {
|
||||||
|
[ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
|
echo $(( ($(date +%s) - $(date -d "$1" +%s)) / 60 / 60 / 24 ))
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || days "$@"
|
||||||
|
|
21
sh/dbusiest
21
sh/dbusiest
|
@ -1,8 +1,15 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
local c d
|
# YES_ZSH
|
||||||
for d in *(FDN); do
|
|
||||||
print $(find $d 2>/dev/null | wc -l) $d
|
dbusiest() {
|
||||||
done | sort -nr | while read c d; do
|
[ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
echo -E $c $d
|
local c d
|
||||||
done
|
for d in *(FDN); do
|
||||||
[ -z $d ] && return 1
|
print $(find $d 2>/dev/null | wc -l) $d
|
||||||
|
done | sort -nr | while read c d; do
|
||||||
|
echo -E $c $d
|
||||||
|
done
|
||||||
|
[ -z $d ] && return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || dbusiest
|
||||||
|
|
13
sh/dfu
13
sh/dfu
|
@ -1,4 +1,11 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
df -xtmpfs | awk '
|
# YES_ZSH
|
||||||
NR==1{printf"%-20s %7s %7s %7s %7s\n","Filesystem","Used","Max","Left","Misc"}
|
|
||||||
NR>1{printf"%-20s %7.2f %7.2f %7.2f %7.2f\n",$6,$3/2^20,($3+$4)/2^20,($4)/2^20,($2-$4-$3)/2^20}'
|
dfu() {
|
||||||
|
[ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
|
df -xtmpfs | awk '
|
||||||
|
NR==1{printf"%-20s %7s %7s %7s %7s\n","Filesystem","Used","Max","Left","Misc"}
|
||||||
|
NR>1{printf"%-20s %7.2f %7.2f %7.2f %7.2f\n",$6,$3/2^20,($3+$4)/2^20,($4)/2^20,($2-$4-$3)/2^20}'
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || dfu
|
||||||
|
|
6
sh/disf
6
sh/disf
|
@ -1,9 +1,13 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# disassembles a function given its symbolic name.
|
# disassembles a function given its symbolic name.
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
function disf() {
|
function disf() {
|
||||||
|
[ $# -le 2 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
local exe="${1:?first argument should be an unstripped executable}"
|
local exe="${1:?first argument should be an unstripped executable}"
|
||||||
local symbol="${2:?second argument should be a function name}"
|
local symbol="${2:?second argument should be a function name}"
|
||||||
# note: relies on GNU sed: https://unix.stackexchange.com/a/78485
|
# note: relies on GNU sed: https://unix.stackexchange.com/a/78485
|
||||||
objdump -d -C --no-show-raw-insn "$exe" | sed '/<'"$symbol"'>:/,/^$/!d;//d'
|
objdump -d -C --no-show-raw-insn "$exe" | sed '/<'"$symbol"'>:/,/^$/!d;//d'
|
||||||
}
|
}
|
||||||
disf "$@"
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || disf "$@"
|
||||||
|
|
79
sh/e
79
sh/e
|
@ -1,50 +1,55 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
local editor=(${=EDITOR})
|
e() {
|
||||||
local running=0
|
local editor=(${=EDITOR})
|
||||||
|
local running=0
|
||||||
|
|
||||||
if [ -n "$MSYSTEM" ]; then
|
if [ -n "$MSYSTEM" ]; then
|
||||||
if ps -f | awk '{print $6}' \
|
if ps -f | awk '{print $6}' \
|
||||||
| grep -o '[^/]*$' | grep -qFx "${editor[1]}"; then
|
| grep -o '[^/]*$' | grep -qFx "${editor[1]}"; then
|
||||||
|
running=1
|
||||||
|
fi
|
||||||
|
elif ps -o comm | grep -qFx "${editor[1]}"; then
|
||||||
running=1
|
running=1
|
||||||
fi
|
fi
|
||||||
elif ps -o comm | grep -qFx "${editor[1]}"; then
|
|
||||||
running=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $running -eq 1 ]; then
|
if [ $running -eq 1 ]; then
|
||||||
printf "%s\n" "${editor[1]} is already running" >&2
|
printf "%s\n" "${editor[1]} is already running" >&2
|
||||||
read -q '?Continue? [y/N] ' _ || { echo; return; }
|
read -q '?Continue? [y/N] ' _ || { echo; return; }
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $# -eq 0 ] || [ -n "$MSYSTEM" ]; then
|
if [ $# -eq 0 ] || [ -n "$MSYSTEM" ]; then
|
||||||
$=EDITOR "$@"
|
$=EDITOR "$@"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local f needroot=0
|
local f needroot=0
|
||||||
for f in "$@"; do
|
for f in "$@"; do
|
||||||
# easy: file exists, we have write permissions
|
# easy: file exists, we have write permissions
|
||||||
[ -w "$f" ] && continue
|
[ -w "$f" ] && continue
|
||||||
|
|
||||||
# easy: file exists, but no write permissions
|
# easy: file exists, but no write permissions
|
||||||
[ -e "$f" ] && { needroot=1; break }
|
[ -e "$f" ] && { needroot=1; break }
|
||||||
|
|
||||||
# hard: file may be in a directory that we can't inspect
|
# hard: file may be in a directory that we can't inspect
|
||||||
local d="$f"
|
local d="$f"
|
||||||
while expr index "$d" / >/dev/null; do
|
while expr index "$d" / >/dev/null; do
|
||||||
d="${d%/*}"
|
d="${d%/*}"
|
||||||
# NOTE: this gets weird with the root directory, not sure how to handle
|
# NOTE: this gets weird with the root directory, not sure how to handle
|
||||||
[ -e "$d" ] && [ ! -w "$d" ] && { needroot=1 && break; }
|
[ -e "$d" ] && [ ! -w "$d" ] && { needroot=1 && break; }
|
||||||
|
done
|
||||||
|
[ $needroot -eq 1 ] && break
|
||||||
|
|
||||||
|
# easy: file just doesn't exist
|
||||||
done
|
done
|
||||||
[ $needroot -eq 1 ] && break
|
|
||||||
|
|
||||||
# easy: file just doesn't exist
|
if [ $needroot -eq 0 ]; then
|
||||||
done
|
$=EDITOR "$@"
|
||||||
|
else
|
||||||
|
sudo -e "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
if [ $needroot -eq 0 ]; then
|
[ "${SOURCING:-0}" -gt 0 ] || e "$@"
|
||||||
$=EDITOR "$@"
|
|
||||||
else
|
|
||||||
sudo -e "$@"
|
|
||||||
fi
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# remote file access (http file-sharing shenanigans)
|
# remote file access (http file-sharing shenanigans)
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
_REMOTE_DOMAIN="https://eaguru.guru"
|
_REMOTE_DOMAIN="https://eaguru.guru"
|
||||||
_REMOTE_DIR="t"
|
_REMOTE_DIR="t"
|
||||||
|
@ -36,3 +37,5 @@ eadelete() {
|
||||||
alias eamv=eamove
|
alias eamv=eamove
|
||||||
alias eacp=eacopy
|
alias eacp=eacopy
|
||||||
alias earm=eadelete
|
alias earm=eadelete
|
||||||
|
|
||||||
|
# TODO: write "ea" interface with subcommands for each action, invoke it.
|
9
sh/echo2
Normal file
9
sh/echo2
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
echo2() {
|
||||||
|
local IFS=" "
|
||||||
|
printf "%s\n" "$*" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || echo2 "$@"
|
9
sh/explore
Normal file
9
sh/explore
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
explore() {
|
||||||
|
[ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
|
explorer "$(cygpath -w "${1:-.}")"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || explore "$@"
|
9
sh/ff
Normal file
9
sh/ff
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
ff() {
|
||||||
|
[ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
|
find "${1:-.}" -type f | fzy
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || ff "$@"
|
12
sh/has
Normal file
12
sh/has
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
has() {
|
||||||
|
if [ -n "$ZSH_VERSION" ]; then
|
||||||
|
whence -p "$1"
|
||||||
|
else
|
||||||
|
which "$1" >/dev/null 2>&1 && which "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || has "$@"
|
8
sh/hex
8
sh/hex
|
@ -1,2 +1,8 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
printf "%08X\n" "$(($@))"
|
# YES_ZSH
|
||||||
|
|
||||||
|
hex() {
|
||||||
|
printf "%08X\n" "$(($@))"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || hex "$@"
|
||||||
|
|
11
sh/ify
Normal file
11
sh/ify
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
ify() {
|
||||||
|
[ $# -ge 2 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; }
|
||||||
|
local ex="$1"
|
||||||
|
shift
|
||||||
|
"$@" | "$ex"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || ify "$@"
|
|
@ -1,4 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
is_empty() {
|
is_empty() {
|
||||||
while read -r; do
|
while read -r; do
|
||||||
[ ! -d "$REPLY" ] && [ -s "$REPLY" ] && return 1
|
[ ! -d "$REPLY" ] && [ -s "$REPLY" ] && return 1
|
||||||
|
@ -7,4 +9,5 @@ is_empty() {
|
||||||
# this needs to skip empty files as well.
|
# this needs to skip empty files as well.
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
is_empty "$@"
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || is_empty "$@"
|
||||||
|
|
5
sh/isup
5
sh/isup
|
@ -1,7 +1,10 @@
|
||||||
#!/usr/bin/zsh
|
#!/usr/bin/zsh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
isup() {
|
isup() {
|
||||||
local c
|
local c
|
||||||
curl -sLI -w '%{http_code}' -o /dev/null "$1" | read -r c
|
curl -sLI -w '%{http_code}' -o /dev/null "$1" | read -r c
|
||||||
[ "${c:0:1}" -eq 2 ]
|
[ "${c:0:1}" -eq 2 ]
|
||||||
}
|
}
|
||||||
isup "$@"
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || isup "$@"
|
||||||
|
|
131
sh/maybesudo
Normal file
131
sh/maybesudo
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
maybesudo_() {
|
||||||
|
local name
|
||||||
|
local env_cleanup=0
|
||||||
|
while getopts ':AEHKPSVbhiklnsvC:U:g:p:r:t:u:' name; do
|
||||||
|
case $name in
|
||||||
|
K|V|k)
|
||||||
|
# K: sure kill
|
||||||
|
# V: version
|
||||||
|
# k: kill
|
||||||
|
note 'maybesudo: your system does not have sudo installed!'
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
|
||||||
|
h)
|
||||||
|
printf "%s\n" 'maybesudo - a dumb utility for systems without sudo'
|
||||||
|
printf "\n"
|
||||||
|
printf "%s\n" 'usage: maybesudo -h | -V'
|
||||||
|
printf "%s\n" 'usage: maybesudo [command]'
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
|
||||||
|
A|E|H|P|S|n|p)
|
||||||
|
# A: askpass
|
||||||
|
# E: preserve environment
|
||||||
|
# H: HOME
|
||||||
|
# P: preserve group vector
|
||||||
|
# S: stdin (password)
|
||||||
|
# n: non-interactive
|
||||||
|
# p: prompt
|
||||||
|
note 'maybesudo: option has no effect --' "'$name'"
|
||||||
|
;;
|
||||||
|
|
||||||
|
C|U|b|g|i|l|r|s|t)
|
||||||
|
# C: close from (fd)
|
||||||
|
# U: other user (in conjunction wiht -l)
|
||||||
|
# b: background
|
||||||
|
# g: group
|
||||||
|
# i: simulate initial login (TODO)
|
||||||
|
# l: list
|
||||||
|
# r: role (SELinux)
|
||||||
|
# s: shell (TODO)
|
||||||
|
# t: type (SELinux)
|
||||||
|
note "maybesudo: unsupported option --" "'$name'"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
u) # user
|
||||||
|
if [ -z "$USER" -o "$OPTARG" != "$USER" ]; then
|
||||||
|
note 'maybesudo: users other than yourself are unsupported!'
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
env_cleanup=1
|
||||||
|
;;
|
||||||
|
|
||||||
|
:)
|
||||||
|
note 'maybesudo: option requires an argument --' "'$OPTARG'"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
default)
|
||||||
|
note 'maybesudo: invalid option --' "'$OPTARG'"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
|
if [ "$env_cleanup" = 1 ]; then
|
||||||
|
(
|
||||||
|
# portably listing exported variable names is virtually impossible
|
||||||
|
# without the blessing of null-terminated strings, so don't even try.
|
||||||
|
# just export the bare minimum that a fairly stock sudo would.
|
||||||
|
|
||||||
|
# $path is special in zsh, so call it pathy instead.
|
||||||
|
local colors display dpkg_colors home hostname krb5ccname \
|
||||||
|
ls_colors pathy ps1 ps2 user username xauthority xauthorization
|
||||||
|
|
||||||
|
[ -z "$COLORS" ] || colors=COLORS="$COLORS"
|
||||||
|
[ -z "$DISPLAY" ] || display=DISPLAY="$DISPLAY"
|
||||||
|
[ -z "$DPKG_COLORS" ] || dpkg_colors=DPKG_COLORS="$DPKG_COLORS"
|
||||||
|
[ -z "$HOME" ] || home=HOME="$HOME"
|
||||||
|
[ -z "$HOSTNAME" ] || hostname=HOSTNAME="$HOSTNAME"
|
||||||
|
[ -z "$KRB5CCNAME" ] || krb5ccname=KRB5CCNAME="$KRB5CCNAME"
|
||||||
|
[ -z "$LS_COLORS" ] || ls_colors=LS_COLORS="$LS_COLORS"
|
||||||
|
[ -z "$PATH" ] || pathy=PATH="$PATH"
|
||||||
|
[ -z "$PS1" ] || ps1=PS1="$PS1"
|
||||||
|
[ -z "$PS2" ] || ps2=PS2="$PS2"
|
||||||
|
[ -z "$USER" ] || user=USER="$USER"
|
||||||
|
[ -z "$USERNAME" ] || username=USERNAME="$USERNAME"
|
||||||
|
[ -z "$XAUTHORITY" ] || xauthority=XAUTHORITY="$XAUTHORITY"
|
||||||
|
[ -z "$XAUTHORIZATION" ] || xauthorization=XAUTHORIZATION="$XAUTHORIZATION"
|
||||||
|
|
||||||
|
# don't eat up precious command space with dumb colors.
|
||||||
|
# xargs --show-limits says:
|
||||||
|
# Maximum length of command we could actually use: 5080
|
||||||
|
[ "${#ls_colors}" -le 1024 ] || ls_colors==
|
||||||
|
|
||||||
|
# sudo also sets SUDO_COMMAND, SUDO_GID, SUDO_UID, SUDO_USER, and MAIL,
|
||||||
|
# but who needs those?
|
||||||
|
|
||||||
|
# env seems to treat arguments of "=" as a no-op across GNU and busybox.
|
||||||
|
env -i \
|
||||||
|
"${colors:-=}" \
|
||||||
|
"${display:-=}" \
|
||||||
|
"${dpkg_colors:-=}" \
|
||||||
|
"${home:-=}" \
|
||||||
|
"${hostname:-=}" \
|
||||||
|
"${krb5ccname:-=}" \
|
||||||
|
"${ls_colors:-=}" \
|
||||||
|
"${pathy:-=}" \
|
||||||
|
"${ps1:-=}" \
|
||||||
|
"${ps2:-=}" \
|
||||||
|
"${user:-=}" \
|
||||||
|
"${username:-=}" \
|
||||||
|
"${xauthority:-=}" \
|
||||||
|
"${xauthorization:-=}" \
|
||||||
|
"$@"
|
||||||
|
)
|
||||||
|
|
||||||
|
else
|
||||||
|
# run it in a subshell so it won't affect ours.
|
||||||
|
( "$@"; )
|
||||||
|
fi
|
||||||
|
|
||||||
|
# don't put any code here or you'll clobber $?.
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || maybesudo_ "$@"
|
|
@ -1,30 +1,35 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
# crontab usage:
|
# crontab usage:
|
||||||
#* * * * * minutemaid 9 cd repo && git pull # runs every nine minutes
|
#* * * * * minutemaid 9 cd repo && git pull # runs every nine minutes
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
local offset=0 opt=
|
minutemaid() {
|
||||||
while getopts 'o:h' opt; do
|
local offset=0 opt=
|
||||||
case $opt in
|
while getopts 'o:h' opt; do
|
||||||
o) offset="$OPTARG";;
|
case $opt in
|
||||||
?) local fd=0
|
o) offset="$OPTARG";;
|
||||||
[ $opt = h ] && fd=0 || fd=2
|
?) local fd=0
|
||||||
echo -E "usage: $0 [-o offset] {interval} [{command} [{args...}]]" >&$fd
|
[ $opt = h ] && fd=0 || fd=2
|
||||||
[ $opt = h ] && return 0 || return 1;;
|
echo -E "usage: $0 [-o offset] {interval} [{command} [{args...}]]" >&$fd
|
||||||
esac
|
[ $opt = h ] && return 0 || return 1;;
|
||||||
done
|
esac
|
||||||
shift $((OPTIND-1))
|
done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
local interval="${1:?no interval specified}"
|
local interval="${1:?no interval specified}"
|
||||||
shift
|
|
||||||
|
|
||||||
local sec="$(date +%s)"
|
|
||||||
let min=sec/60+offset
|
|
||||||
let mod=min%interval
|
|
||||||
if [ $# -gt 0 ]; then
|
|
||||||
local cmd="${1}"
|
|
||||||
shift
|
shift
|
||||||
|
|
||||||
[ $mod -eq 0 ] && "$cmd" "$@"
|
local sec="$(date +%s)"
|
||||||
else
|
let min=sec/60+offset
|
||||||
[ $mod -eq 0 ] && return 0 || return 1
|
let mod=min%interval
|
||||||
fi
|
if [ $# -gt 0 ]; then
|
||||||
|
local cmd="${1}"
|
||||||
|
shift
|
||||||
|
|
||||||
|
[ $mod -eq 0 ] && "$cmd" "$@"
|
||||||
|
else
|
||||||
|
[ $mod -eq 0 ] && return 0 || return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || minutemaid "$@"
|
||||||
|
|
66
sh/monitor
66
sh/monitor
|
@ -1,35 +1,41 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
local bottom=0 strip=0 interval=2 opt=
|
# YES_ZSH
|
||||||
while getopts 'fsn:h' opt; do
|
|
||||||
case $opt in
|
|
||||||
f) bottom=1;; # align with bottom of terminal
|
|
||||||
s) strip=1;; # strip last character assuming it's a newline
|
|
||||||
n) interval="$OPTARG";;
|
|
||||||
?) echo -E "usage: $0 [-fs] [-n {period}] {command} [{args...}]"
|
|
||||||
[ $opt = h ] && return 0 || return 1;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
shift $((OPTIND-1))
|
|
||||||
|
|
||||||
local cmd=${1:?no command specified}
|
monitor() {
|
||||||
shift
|
local bottom=0 strip=0 interval=2 opt=
|
||||||
|
while getopts 'fsn:h' opt; do
|
||||||
|
case $opt in
|
||||||
|
f) bottom=1;; # align with bottom of terminal
|
||||||
|
s) strip=1;; # strip last character assuming it's a newline
|
||||||
|
n) interval="$OPTARG";;
|
||||||
|
?) echo -E "usage: $0 [-fs] [-n {period}] {command} [{args...}]"
|
||||||
|
[ $opt = h ] && return 0 || return 1;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
function _monclear() {
|
local cmd=${1:?no command specified}
|
||||||
[ $bottom -eq 1 ] && printf ${(l:$((LINES*2))::\n:)}
|
shift
|
||||||
}
|
|
||||||
function _monfit() {
|
function _monclear() {
|
||||||
if [ $strip -eq 1 ]; then
|
[ $bottom -eq 1 ] && printf ${(l:$((LINES*2))::\n:)}
|
||||||
tail -$((LINES)) | head -c-1
|
}
|
||||||
else
|
function _monfit() {
|
||||||
tail -$((LINES-1))
|
if [ $strip -eq 1 ]; then
|
||||||
fi
|
tail -$((LINES)) | head -c-1
|
||||||
|
else
|
||||||
|
tail -$((LINES-1))
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
local stop=0
|
||||||
|
trap stop=1 INT
|
||||||
|
echo -en "\e[H\e[2J"
|
||||||
|
while [ $stop -eq 0 ]; do
|
||||||
|
echo -en "\e[1J\e[H"
|
||||||
|
{ _monclear; "$cmd" "$@" 2>&1 } | fold -w $COLUMNS | _monfit
|
||||||
|
sleep "$interval" || break
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
local stop=0
|
[ "${SOURCING:-0}" -gt 0 ] || monitor "$@"
|
||||||
trap stop=1 INT
|
|
||||||
echo -en "\e[H\e[2J"
|
|
||||||
while [ $stop -eq 0 ]; do
|
|
||||||
echo -en "\e[1J\e[H"
|
|
||||||
{ _monclear; "$cmd" "$@" 2>&1 } | fold -w $COLUMNS | _monfit
|
|
||||||
sleep "$interval" || break
|
|
||||||
done
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
# the first expression is taken from this FAQ:
|
# the first expression is taken from this FAQ:
|
||||||
# https://perldoc.perl.org/perlfaq6.html#How-do-I-use-a-regular-expression-to-strip-C-style-comments-from-a-file%3f
|
# https://perldoc.perl.org/perlfaq6.html#How-do-I-use-a-regular-expression-to-strip-C-style-comments-from-a-file%3f
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
noccom() {
|
noccom() {
|
||||||
[ -s ~/opt/local/bin/noccom ] || cat > ~/opt/local/bin/noccom <<EOF
|
[ -s ~/opt/local/bin/noccom ] || cat > ~/opt/local/bin/noccom <<EOF
|
||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
|
@ -45,4 +47,5 @@ EOF
|
||||||
|
|
||||||
perl ~/opt/local/bin/noccom "$@"
|
perl ~/opt/local/bin/noccom "$@"
|
||||||
}
|
}
|
||||||
noccom "$@"
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || noccom "$@"
|
||||||
|
|
9
sh/note
Normal file
9
sh/note
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
note() {
|
||||||
|
local IFS=" "
|
||||||
|
printf "\033[1m%s\033[0m\n" "$*" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || note "$@"
|
10
sh/now
10
sh/now
|
@ -1,7 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
now() {
|
now() {
|
||||||
local dt=
|
[ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
|
local dt
|
||||||
local fmt='+%F_%T_%N'
|
local fmt='+%F_%T_%N'
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
dt="$(date -u "$fmt")"
|
dt="$(date -u "$fmt")"
|
||||||
|
@ -11,12 +13,12 @@ now() {
|
||||||
dt="$(date -u -d "$1" "$fmt")"
|
dt="$(date -u -d "$1" "$fmt")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local F= T= N=
|
local F T N
|
||||||
F=${dt%%_*}
|
F=${dt%%_*}
|
||||||
T=${dt#*_}
|
T=${dt#*_}
|
||||||
T=${T%_*}
|
T=${T%_*}
|
||||||
N=${dt##*_}
|
N=${dt##*_}
|
||||||
local H= M= S=
|
local H M S
|
||||||
H=${T%%:*}
|
H=${T%%:*}
|
||||||
M=${T#*:}
|
M=${T#*:}
|
||||||
M=${M%:*}
|
M=${M%:*}
|
||||||
|
@ -36,4 +38,4 @@ now() {
|
||||||
echo "${F}_${ms}"
|
echo "${F}_${ms}"
|
||||||
}
|
}
|
||||||
|
|
||||||
now "$@"
|
[ "${SOURCING:-0}" -gt 0 ] || now "$@"
|
||||||
|
|
14
sh/pacbm
14
sh/pacbm
|
@ -1,5 +1,11 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
expac -s '%m %n' | awk '
|
# YES_ZSH
|
||||||
{t+=$1;printf("%8.2fM %s\n",$1/(1024*1024),$2)}
|
|
||||||
END{printf("%8.2fM\n",t/(1024*1024))}
|
pacbm() {
|
||||||
' | sort -n
|
expac -s '%m %n' | awk '
|
||||||
|
{t+=$1;printf("%8.2fM %s\n",$1/(1024*1024),$2)}
|
||||||
|
END{printf("%8.2fM\n",t/(1024*1024))}
|
||||||
|
' | sort -n
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || pacbm "$@"
|
||||||
|
|
14
sh/pause
14
sh/pause
|
@ -1,5 +1,11 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
[ -n "${ZSH_VERSION:-}" ] \
|
# YES_ZSH
|
||||||
&& read -sk '?Press any key to continue
|
|
||||||
' || read -n1 -u 1 -sp 'Press any key to continue
|
pause() {
|
||||||
'
|
[ -n "${ZSH_VERSION:-}" ] \
|
||||||
|
&& read -sk '?Press any key to continue
|
||||||
|
' || read -n1 -u 1 -sp 'Press any key to continue
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || pause "$@"
|
||||||
|
|
9
sh/pegg
Normal file
9
sh/pegg
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
pegg() {
|
||||||
|
[ $# -ge 2 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; }
|
||||||
|
pippy "https://github.com/$1/$2/tarball/${3:-master}#egg=$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || pegg "$@"
|
12
sh/pippy
Normal file
12
sh/pippy
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/usr/bin/env
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
#. ~/sh/maybesudo
|
||||||
|
#. ~/sh/has
|
||||||
|
|
||||||
|
pippy() {
|
||||||
|
local sudo="$(has sudo || echo maybesudo_)"
|
||||||
|
"$sudo" py -m pip install --upgrade --upgrade-strategy only-if-needed "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || pippy "$@"
|
16
sh/pre
16
sh/pre
|
@ -1,6 +1,12 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
if [ -n "${ZSH_VERSION:-}" ]; then
|
# YES_ZSH
|
||||||
${CC:-gcc} -dM -E - $=CPPFLAGS $=CFLAGS $=LDFLAGS < /dev/null
|
|
||||||
else
|
pre() {
|
||||||
${CC:-gcc} -dM -E - $CPPFLAGS $CFLAGS $LDFLAGS < /dev/null
|
if [ -n "${ZSH_VERSION:-}" ]; then
|
||||||
fi
|
${CC:-gcc} -dM -E - $=CPPFLAGS $=CFLAGS $=LDFLAGS < /dev/null
|
||||||
|
else
|
||||||
|
${CC:-gcc} -dM -E - $CPPFLAGS $CFLAGS $LDFLAGS < /dev/null
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || pre "$@"
|
||||||
|
|
14
sh/psbm
14
sh/psbm
|
@ -1,5 +1,11 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
ps axco rss,pid,command | awk '
|
# YES_ZSH
|
||||||
NR>1&&$1>0{t+=$1;printf("%8.2fM %7d %s\n",$1/1024,$2,$3)}
|
|
||||||
END{printf("%8.2fM\n",t/1024)}
|
psbm() {
|
||||||
' | sort -n
|
ps axco rss,pid,command | awk '
|
||||||
|
NR>1&&$1>0{t+=$1;printf("%8.2fM %7d %s\n",$1/1024,$2,$3)}
|
||||||
|
END{printf("%8.2fM\n",t/1024)}
|
||||||
|
' | sort -n
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || psbm "$@"
|
||||||
|
|
|
@ -1,2 +1,8 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
find -maxdepth 1 -type d \( -path '/root' -prune -o -print \) | tail -n+2 | shuf | head -1
|
# YES_ZSH
|
||||||
|
|
||||||
|
randir() {
|
||||||
|
find -maxdepth 1 -type d \( -path '/root' -prune -o -print \) | tail -n+2 | shuf | head -1
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || randir "$@"
|
||||||
|
|
8
sh/refresh
Normal file
8
sh/refresh
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
refresh() {
|
||||||
|
hash -r
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || refresh "$@"
|
3
sh/rs
3
sh/rs
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
# rs: record screen
|
# rs: record screen
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
rs() {
|
rs() {
|
||||||
set -e
|
set -e
|
||||||
|
@ -67,4 +68,4 @@ rs() {
|
||||||
$o_overwrite "$extless.enc.$ext"
|
$o_overwrite "$extless.enc.$ext"
|
||||||
}
|
}
|
||||||
|
|
||||||
rs "$@"
|
[ "${SOURCING:-0}" -gt 0 ] || rs "$@"
|
||||||
|
|
3
sh/sc
3
sh/sc
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
. ~/.ea
|
|
||||||
|
. ~/.ea # FIXME: don't do this? somehow?
|
||||||
|
|
||||||
sc_shorten() {
|
sc_shorten() {
|
||||||
REPLY="${1:2:2}${1:5:2}${1:8:2}${1:11:12}"
|
REPLY="${1:2:2}${1:5:2}${1:8:2}${1:11:12}"
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
scramble() {
|
scramble() {
|
||||||
local eggs='s/@\(\w\)\(\w\)\(\w\)/@\3\1@\2/g'
|
local eggs='s/@\(\w\)\(\w\)\(\w\)/@\3\1@\2/g'
|
||||||
sed \
|
sed \
|
||||||
|
@ -7,3 +9,5 @@ scramble() {
|
||||||
-e "$eggs" -e "$eggs" -e "$eggs" -e "$eggs" \
|
-e "$eggs" -e "$eggs" -e "$eggs" -e "$eggs" \
|
||||||
-e 's/@//g'
|
-e 's/@//g'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || scramble "$@"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
screeny() {
|
screeny() {
|
||||||
local user="${1:?needs arg for user name}"
|
local user="${1:?needs arg for user name}"
|
||||||
|
@ -14,4 +15,4 @@ screeny() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
screeny "$@"
|
[ "${SOURCING:-0}" -gt 0 ] || screeny "$@"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
scropt() {
|
scropt() {
|
||||||
local now=
|
local now=
|
||||||
|
@ -7,4 +8,5 @@ scropt() {
|
||||||
scrot "$fn" -e "optipng -quiet \$f" "$@"
|
scrot "$fn" -e "optipng -quiet \$f" "$@"
|
||||||
echo "$fn"
|
echo "$fn"
|
||||||
}
|
}
|
||||||
scropt "$@"
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || scropt "$@"
|
||||||
|
|
30
sh/similar
30
sh/similar
|
@ -1,13 +1,19 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
awk '
|
# YES_ZSH
|
||||||
{
|
|
||||||
i=0
|
similar() {
|
||||||
split($0,a,"")
|
awk '
|
||||||
split(L,b,"")
|
{
|
||||||
for (c in a)
|
i=0
|
||||||
if (a[c]==b[c]) i++
|
split($0,a,"")
|
||||||
else break
|
split(L,b,"")
|
||||||
#print substr($0,1,i) "\033[7m" substr($0,i+1) "\033[0m"
|
for (c in a)
|
||||||
print "\033[31m" substr($0,1,i) "\033[0m" substr($0,i+1)
|
if (a[c]==b[c]) i++
|
||||||
L=$0
|
else break
|
||||||
}'
|
#print substr($0,1,i) "\033[7m" substr($0,i+1) "\033[0m"
|
||||||
|
print "\033[31m" substr($0,1,i) "\033[0m" substr($0,i+1)
|
||||||
|
L=$0
|
||||||
|
}'
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || similar "$@"
|
||||||
|
|
8
sh/slit
8
sh/slit
|
@ -1,3 +1,9 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
# from https://github.com/sorin-ionescu/prezto/
|
# from https://github.com/sorin-ionescu/prezto/
|
||||||
awk "{ print ${(j:,:):-\$${^@}} }"
|
# YES_ZSH
|
||||||
|
|
||||||
|
slit() {
|
||||||
|
awk "{ print ${(j:,:):-\$${^@}} }"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || slit "$@"
|
||||||
|
|
8
sh/slitt
8
sh/slitt
|
@ -1,4 +1,10 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
# via: https://github.com/sorin-ionescu/prezto/
|
# via: https://github.com/sorin-ionescu/prezto/
|
||||||
# this version uses tabs for input/output field separators.
|
# this version uses tabs for input/output field separators.
|
||||||
awk "BEGIN { FS=\"\\t\"; OFS=\"\\t\" } { print ${(j:,:):-\$${^@}} }"
|
# YES_ZSH
|
||||||
|
|
||||||
|
slitt() {
|
||||||
|
awk "BEGIN { FS=\"\\t\"; OFS=\"\\t\" } { print ${(j:,:):-\$${^@}} }"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || slitt "$@"
|
||||||
|
|
3
sh/sram
3
sh/sram
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
sram() {
|
sram() {
|
||||||
die() {
|
die() {
|
||||||
|
@ -47,4 +48,4 @@ sram() {
|
||||||
revend "$out"
|
revend "$out"
|
||||||
}
|
}
|
||||||
|
|
||||||
sram "$@"
|
[ "${SOURCING:-0}" -gt 0 ] || sram "$@"
|
||||||
|
|
42
sh/stfu
Normal file
42
sh/stfu
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
#. ~/sh/echo2 # FIXME
|
||||||
|
#. ~/sh/note # FIXME
|
||||||
|
|
||||||
|
stfu() {
|
||||||
|
# NOTE: don't use stfu for handling sensitive data or commands!
|
||||||
|
# use it for 7zip.
|
||||||
|
[ $# -gt 0 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; }
|
||||||
|
local temp="${TMP:-/tmp}/stfu"
|
||||||
|
|
||||||
|
local time="$(date -u '+%s')"
|
||||||
|
[ $? -eq 0 ] || { printf "%s\n" "$0: failed to get current time" >&2; return 1; }
|
||||||
|
|
||||||
|
mkdir -p "$temp" || { printf "%s\n" "$0: failed to create temp directory" >&2; return 1; }
|
||||||
|
|
||||||
|
while [ -e "$temp/out_$time" -o -e "$temp/err_$time" ]; do time=$((time+1)); done
|
||||||
|
local out="$temp/out_$time"
|
||||||
|
local err="$temp/err_$time"
|
||||||
|
|
||||||
|
#local out="$(mktemp -t -p "$temp" out_XXXXXX)"
|
||||||
|
#[ $? -eq 0 ] || { printf "%s\n" "$0: failed to create temp file" >&2; return 1; }
|
||||||
|
#local err="$(mktemp -t -p "$temp" err_XXXXXX)"
|
||||||
|
#[ $? -eq 0 ] || { printf "%s\n" "$0: failed to create temp file" >&2; return 1; }
|
||||||
|
|
||||||
|
local ret=0
|
||||||
|
"$@" > "$out" 2> "$err" || ret=$?
|
||||||
|
if [ $ret -ne 0 ]; then
|
||||||
|
printf "command failed with exit status %s:\n" $ret >&2
|
||||||
|
echo2 "$@"
|
||||||
|
echo2
|
||||||
|
note '$ tail -n 20' "$out"
|
||||||
|
tail -n 20 "$out" >&2
|
||||||
|
echo2
|
||||||
|
note '$ tail -n 20' "$err"
|
||||||
|
tail -n 20 "$err" >&2
|
||||||
|
fi
|
||||||
|
return $ret
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || stfu "$@"
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env false
|
||||||
# awful things
|
# awful things
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
MPV_STREAM_FLAGS="--quiet --autofit=1280x720 --loop-playlist=no --no-resume-playback --no-sub \
|
MPV_STREAM_FLAGS="--quiet --autofit=1280x720 --loop-playlist=no --no-resume-playback --no-sub \
|
||||||
--no-initial-audio-sync --mc=0.02 --autosync=30"
|
--no-initial-audio-sync --mc=0.02 --autosync=30"
|
||||||
|
@ -111,5 +112,3 @@ asmr() {
|
||||||
_M_PROCESS="acompressor=threshold=0.001:ratio=1.33:attack=900:release=6000:makeup=6:knee=8:mix=0.9,alimiter" \
|
_M_PROCESS="acompressor=threshold=0.001:ratio=1.33:attack=900:release=6000:makeup=6:knee=8:mix=0.9,alimiter" \
|
||||||
yt "$@" --volume=90 --ytdl-format=251/300/best
|
yt "$@" --volume=90 --ytdl-format=251/300/best
|
||||||
}
|
}
|
||||||
|
|
||||||
[ -e "$HOME/.nara" ] && . "$HOME/.nara"
|
|
12
sh/sum
Normal file
12
sh/sum
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
sum() {
|
||||||
|
local sum=0
|
||||||
|
for i; do
|
||||||
|
sum=$((sum+i))
|
||||||
|
done
|
||||||
|
echo "$sum"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || sum "$@"
|
12
sh/sv
12
sh/sv
|
@ -1,4 +1,10 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
awk "-F${1:- }" '
|
# YES_ZSH
|
||||||
NF>1{f[$1]=substr($0,length($1)+1+length(FS))}END{for(k in f)print k FS f[k]}
|
|
||||||
'
|
sv() {
|
||||||
|
awk "-F${1:- }" '
|
||||||
|
NF>1{f[$1]=substr($0,length($1)+1+length(FS))}END{for(k in f)print k FS f[k]}
|
||||||
|
'
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || sv "$@"
|
||||||
|
|
5
sh/tpad
5
sh/tpad
|
@ -1,8 +1,11 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
tpad() {
|
tpad() {
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
gm convert -bordercolor "#000000FF" -border 1x1 "$1" "${1/.png/}.tt.png";
|
gm convert -bordercolor "#000000FF" -border 1x1 "$1" "${1/.png/}.tt.png";
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
tpad "$@"
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || tpad "$@"
|
||||||
|
|
9
sh/trash
Normal file
9
sh/trash
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
trash() {
|
||||||
|
[ $# -le 1 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
|
dd status=none if=/dev/random bs=1 count="${1:?missing count argument}"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || trash "$@"
|
10
sh/trunc
10
sh/trunc
|
@ -1,3 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
COLUMNS=${COLUMNS:-$(tput cols)}
|
# YES_ZSH
|
||||||
awk -vL=${1:-$COLUMNS} '{e=length>L?"…":"";print substr($0,0,L-(e?1:0)) e}'
|
|
||||||
|
trunc() {
|
||||||
|
COLUMNS=${COLUMNS:-$(tput cols)}
|
||||||
|
awk -vL=${1:-$COLUMNS} '{e=length>L?"…":"";print substr($0,0,L-(e?1:0)) e}'
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || trunc "$@"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
unscreen() {
|
unscreen() {
|
||||||
local pids="$(screen -ls | fgrep "$1" | cut -d. -f1)"
|
local pids="$(screen -ls | fgrep "$1" | cut -d. -f1)"
|
||||||
|
@ -9,4 +10,4 @@ unscreen() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
unscreen "$@"
|
[ "${SOURCING:-0}" -gt 0 ] || unscreen "$@"
|
||||||
|
|
35
sh/wat
Normal file
35
sh/wat
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/usr/bin/env zsh
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
# wat - a better and recursive which/whence
|
||||||
|
# via: https://leahneukirchen.org/dotfiles/tools.html
|
||||||
|
wat() {
|
||||||
|
( # constrain unalias
|
||||||
|
for cmd; do
|
||||||
|
if (( $+aliases[$cmd] )); then
|
||||||
|
printf '%s: aliased to %s\n' $cmd $aliases[$cmd]
|
||||||
|
local -a words=(${${(z)aliases[$cmd]}:#(*=*|rlwrap|noglob|command)})
|
||||||
|
unalias $cmd
|
||||||
|
if [[ $words[1] == '\'* ]]; then
|
||||||
|
words[1]=${words[1]#'\'}
|
||||||
|
unalias $words[1] 2>/dev/null
|
||||||
|
fi
|
||||||
|
wat $words[1]
|
||||||
|
elif (( $+functions[$cmd] )); then
|
||||||
|
whence -v $cmd
|
||||||
|
whence -f $cmd
|
||||||
|
elif (( $+commands[$cmd] )); then
|
||||||
|
wat $commands[$cmd]
|
||||||
|
elif [[ -h $cmd ]]; then
|
||||||
|
file $cmd
|
||||||
|
wat $cmd:A
|
||||||
|
elif [[ -x $cmd ]]; then
|
||||||
|
file $cmd
|
||||||
|
else
|
||||||
|
which $cmd
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || wat "$@"
|
14
sh/wipe
Normal file
14
sh/wipe
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# YES_ZSH
|
||||||
|
|
||||||
|
wipe() {
|
||||||
|
# TODO: rename because wipe(1) already exists.
|
||||||
|
[ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
|
clear
|
||||||
|
clear # twice because mintty is weird
|
||||||
|
echo "\033[30m\033[107m"
|
||||||
|
printf "*%.0s" {1..$COLUMNS}
|
||||||
|
echo "\033[0m\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "${SOURCING:-0}" -gt 0 ] || wipe "$@"
|
Loading…
Reference in New Issue
Block a user