Skip to content

Instantly share code, notes, and snippets.

View GeneralD's full-sized avatar
💭
Alcohol makes better code 🥃

YUMENOSUKE GeneralD

💭
Alcohol makes better code 🥃
View GitHub Profile
function skim-nerdfont() {
(( $+commands[ascii2uni] )) || { echo "ascii2uni is not installed"; return 1; }
(( $+commands[rg] )) || { echo "rg is not installed"; return 1; }
local list=$(curl -s https://www.nerdfonts.com/cheat-sheet | rg '^ *\"(.+)\"\: ?\"([a-f0-9]{4})\",?$' --color=never --replace '\u$2 $1' | ascii2uni -a U -q)
local select=$(echo $list | sk --query="$1" --multi)
echo $select | awk '{print $1}' | tr '\n' ' ' | pbcopy
zle reset-prompt;
}
#!/usr/bin/env zsh
# helper functions for https://github.com/Aloxaf/gencomp
clean-gencomp() {
for file in $GENCOMP_DIR/*; do
local cmd=$(basename $file | sed 's/^_//')
command -v $cmd &>/dev/null && continue
echo "Remove completion for $cmd? [y/N]"
read -q
#!/usr/bin/env zsh
keybind_as_widget() {
local hash=$(echo $2 | md5)
local widget_name="__widget_$hash"
eval "function $widget_name() { $2; }"
zle -N $widget_name
bindkey $1 $widget_name
}
function skim-gitignore() {
local api="https://www.toptal.com/developers/gitignore/api"
local gi=$(curl -sfL $api/list | tr "," "\n" | sk --query="$1" -m --preview "curl -sfLw '\n' $api/{} | bat --style=numbers --color=always --language='Git Ignore'")
if [[ $gi ]]; then
for prog in $(echo $gi); do;
curl -sfLw '\n' "$api/$prog" >> .gitignore;
echo "Added $prog to .gitignore";
done;
fi
#!/usr/bin/env zsh
# functions
function skim-brew-install() {
local inst=$(brew formulae | sk --query="$1" -m --preview 'brew info {}' --bind 'ctrl-space:execute-silent(brew home {})')
if [[ $inst ]]; then
for prog in $(echo $inst); do; brew install $prog; done;
fi
}
#!/usr/bin/env zsh
skim_browser_bookmark_search() {
bookmarks_path=`\ls ~/Library/Application\ Support/*/*/Default/Bookmarks -t1 | head -n 1`
jq_script='
def ancestors: while(. | length >= 2; del(.[-1,-2]));
. as $in | paths(.url?) as $key | $in | getpath($key) | {name,url, path: [$key[0:-2] | ancestors as $a | $in | getpath($a) | .name?] | reverse | join("/") } | .path + "/" + .name + "\t" + .url'
(( $+commands[w3m] )) && local fetch="w3m -dump" || local fetch="curl -sfL"
jq -r "$jq_script" < "$bookmarks_path" \
zstyle ':filter-select' case-insensitive yes
zstyle ':filter-select' extended-search yes
zstyle ':filter-select' hist-find-no-dups yes
zstyle ':filter-select' rotate-list yes
bindkey '^z1' zaw-git-branches
bindkey '^z2' zaw-git-files
bindkey '^z3' zaw-git-files-legacy
bindkey '^z4' zaw-git-log
bindkey '^z5' zaw-git-recent-all-branches
type op &>/dev/null && {
eval "$(op completion zsh)" && compdef _op op
[ -f ~/.config/op/plugins.sh ] && source ~/.config/op/plugins.sh
# enable auto-completion through op plugins
local plugins=($(\ls -1 ~/.config/op/plugins/used_items | sed 's/.[^.]*$//'))
for plugin in $plugins; do
eval "
function _${plugin}_wrapped() {
op plugin run -- $plugin \$@
# flippy
if which flippy 1>/dev/null; then
# usage: "F string" or "echo string | F"
alias -g F=__flippy
__flippy () {
if [[ $# > 0 ]]; then
flippy $@
else
local s
while read s; do
import Foundation
import UIKit
@IBDesignable class __CustomView__: UIView {
@IBInspectable var labelText: String = "" {
didSet {
label.text = labelText
}
}