Skip to content

Instantly share code, notes, and snippets.

# Restore your backed up nvim config. Use the backup-nvim.zsh script to create the backup.
restore-nvim() {
local backup_array=(${(f)"$(command ls -1d ~/.config/nvim.* | sort -nr | sed -e 's/.*nvim/nvim/')"})
if [ $#backup_array = 0 ]; then
echo "No backup directory found"
return 1
fi
for ((i = 1; i <= $#backup_array; i++)) print -r -- "[$i] $backup_array[i]"
# backup my nvim config
# backup my neovim config. you can restore the config by using restore-nvim.zsh
backup-nvim() {
local timestamp=$(date "+%Y-%m-%d-%H%M")
echo "Backup following directories"
echo " ~/.config/nvim => ~/.config/nvim.${timestamp}"
echo " ~/.local/share/nvim => ~/.local/share/nvim.${timestamp}"
echo " ~/.local/state/nvim => ~/.local/state/nvim.${timestamp}"
echo " ~/.cache/nvim => ~/.cache/nvim.${timestamp}"
@funasoul
funasoul / ffscreencast.sh
Last active October 15, 2022 20:10
ffmpeg だけでカメラONのスクリーンキャストを収録 for macOS, Linux and OpenBSD
#!/usr/bin/env zsh
_has () {
return $( whence $1 &>/dev/null )
}
getresolution () {
# returns current resolution
if [[ "$OSTYPE" == "darwin"* ]]; then
system_profiler SPDisplaysDataType | awk '/Resolution:/{print $2 "x" $4}'
@funasoul
funasoul / get_resolution.sh
Last active October 15, 2022 17:22
macOS, Linux, OpenBSD等で画面の解像度を取得
#!/usr/bin/env zsh
_has () {
return $( whence $1 &>/dev/null )
}
getresolution () {
# returns current resolution
if [[ "$OSTYPE" == "darwin"* ]]; then
system_profiler SPDisplaysDataType | awk '/Resolution:/{print $2 "x" $4}'
@funasoul
funasoul / update-unbound-blocklist.sh
Last active January 6, 2024 06:32 — forked from takuya/update-unbound-blocklist.sh
unboundのdnsブロッキングリストを更新する。for OpenBSD
#!/usr/bin/env zsh
## @since 2020-05-15
## @last 2021-01-05
## @author takuya
## unbound にブロッキング
## ブロッキングするURLを定期的に更新する
function update_domain_lists(){
update280blocker
@funasoul
funasoul / git-add-screenshot.zsh
Last active November 14, 2022 05:58
When attaching an image to the README.md of a repository such as GitHub or GitLab, I want to push the image to another branch (ex. images) and put the URL of the image file in the README.md to avoid polluting the master repository. Since it was tedious to do it by hand every time, I wrote a zsh function to do this.
git-add-screenshot () {
# I need colors!
autoload -Uz colors;
colors
if [ $# -lt 1 ]; then
echo "Usage: $0 imagefile [branch_name (default: images)]"
echo " Create 'images (by default)' branch and push image file to GitHub/GitLab."
echo " The URL to pushed image file is also copied to your clipboard."
echo " (ex.) $0 screenshot.png"
return 1
@funasoul
funasoul / bindify.py
Last active October 30, 2021 15:44 — forked from gmr/bindify.py
Convert tinydns zone files to bind
#!/usr/bin/env python
import collections
import datetime
from os import path
import pickle
import sys
if len(sys.argv) < 2:
print("Usage: bindify.py zonefile")
sys.exit(0)
@funasoul
funasoul / port.sh
Last active February 4, 2021 18:38
apt とか yum のオプションを覚えるのが面倒だったので MacPorts のコマンドで動くように。~/.zshrc に入れておく。
if [[ "$OSTYPE" == "linux-gnu" ]]
then
export DISTRO=$(lsb_release -si)
fi
port_usage() {
echo "port: A wrapper function for $1."
echo "Supported commands:"
echo " port clean"
echo " port contens \$package"
@funasoul
funasoul / datelsit.py
Last active October 28, 2020 16:01
Google Form で日程調整をする時に便利。Google Form でチェックボックスにして、以下のスクリプトの実行結果をペーストするだけ。
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# -*- coding: utf-8 -*-
#
# Last modified: Thu, 29 Oct 2020 00:50:55 +0900
from datetime import timedelta, date
import locale
# https://stackoverflow.com/a/1060330
def daterange(start_date, end_date):
# A zsh function which will check my proxy configuration.
# Runs only on macOS.
proxycheck() {
local red=`tput setaf 1; tput bold`
local green=`tput setaf 2; tput bold`
local cyan=`tput setaf 6; tput bold`
local reset=`tput sgr0`
local systemflag=0
networksetup -listallnetworkservices | while read line
do