Skip to content

Instantly share code, notes, and snippets.

View Hayao0819's full-sized avatar

Yamada Hayao Hayao0819

View GitHub Profile
@Hayao0819
Hayao0819 / esc.sh
Created October 19, 2022 05:40
エスケープシーケンスで画面制御する関数
#!/usr/bin/env bash
ClearScreen() { printf "\033[2J" ; }
ClearRight() { printf "\033[0K" ; }
ClearLeft() { printf "\033[1K" ; }
ClearLine() { printf "\033[2K" ; }
MoveCursor() { printf "\033[%d;%dH" "$1" "$2" ; }
MoveCursorUp() { printf "\033[%dA" "$1" ; }
MoveCursorDown() { printf "\033[%dB" "$1" ; }
MoveCursorRight() { printf "\033[%dC" "$1" ; }
MoveCursorLeft() { printf "\033[%dD" "$1" ; }
@Hayao0819
Hayao0819 / select-min.sh
Last active November 1, 2022 01:25
インタラクティブな選択メニュー
#!/usr/bin/env bash
CaptureSpecialKeys(){
local SELECTION rest
IFS= read -r -n1 -s SELECTION
#echo "$SELECTION" | hexdump >&2
if [[ $SELECTION == $'\x1b' ]]; then
read -r -n2 -s rest
SELECTION+="$rest"
@Hayao0819
Hayao0819 / select.sh
Created October 19, 2022 04:04
シェルスクリプトで上下左右キーを検知する
#!/usr/bin/env bash
while IFS= read -r -n1 -s SELECTION && [[ -n "$SELECTION" ]]; do
if [[ $SELECTION == $'\x1b' ]]; then
read -r -n2 -s rest
SELECTION+="$rest"
fi
case $SELECTION in
$'\x1b\x5b\x41') #up arrow
@Hayao0819
Hayao0819 / git-sparse.sh
Created September 6, 2022 13:54
Gitから一部のディレクトリのみをクローンします(gitコマンドが必要です)
#!/usr/bin/env bash
# CurrentVersion >= 5
if [ -z "$BASH_VERSION" ]; then
echo "This script works only Bash 5 or higher."
exit 1
elif ! [[ "${BASH_VERSINFO[0]}" -ge 5 ]]; then
echo "Error: Your Bash version is not supported by this script." >&2
exit 1
fi
@Hayao0819
Hayao0819 / elist
Created August 29, 2022 10:18
Emergeでパッケージの一覧を取得するシェルスクリプト
#!/usr/bin/env bash
# shellcheck source=/dev/null
source /dev/stdin < <(curl -sL "https://raw.githubusercontent.com/Hayao0819/FasBashLib/26e244d6f3839bcf159787dfd3e230df39e4500c/fasbashlib.sh")
Fsblib.RequireLib "BetterShell" "ParseArg" "Ini" "Emerge" "Array"
# Initial variable
SpecifiedRepo=()
#PrintRepoName=false
@Hayao0819
Hayao0819 / rebootos
Last active August 29, 2022 10:52
指定したOSで再起動するスクリプト
#!/usr/bin/env bash
set -Eeu -o pipefail
# shellcheck source=/dev/null
source /dev/stdin < <(curl -sL "https://github.com/Hayao0819/FasBashLib/releases/download/v0.2.5/fasbashlib.sh")
(( "$UID" == 0 )) || { Msg.Err "Please run as root."; exit 1; }
readarray -t EntryList < <(awk -F\' '/menuentry / {print $2}' /boot/grub/grub.cfg | grep -v "^$")
LastEntry=$(
last="$(grub-editenv list | cut -d "=" -f 2-)"
[[ -n "${last-""}" ]] || exit 0
eval "Array=($(grep "$last" /boot/grub/grub.cfg))"
@Hayao0819
Hayao0819 / config-gentoo-5.19.4-20220829
Last active August 29, 2022 07:38
Gentoo Linux ZEN Kernel 5.18.16-20220823
#
# Automatically generated file; DO NOT EDIT.
# Linux/x86 5.19.4-gentoo Kernel Configuration
#
CONFIG_CC_VERSION_TEXT="gcc (Gentoo 12.2.0 p1) 12.2.0"
CONFIG_CC_IS_GCC=y
CONFIG_GCC_VERSION=120200
CONFIG_CLANG_VERSION=0
CONFIG_AS_IS_GNU=y
CONFIG_AS_VERSION=23800
@Hayao0819
Hayao0819 / mkinitrd
Last active August 14, 2022 06:35
dracutをインストールされている全てのカーネルで実行するスクリプト
#!/usr/bin/env bash
set -euo pipefail
Force=false
# shellcheck source=/dev/null
#source <(curl -sL https://raw.githubusercontent.com/Hayao0819/FasBashLib/build-0.2.x/fasbashlib.sh)
PrintArray(){ printf '%s\n' "${@}"; }
#!/usr/bin/env python3
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
#:: License
#
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
@Hayao0819
Hayao0819 / ArchNews.sh
Last active August 3, 2022 07:34
Arch Linuxの最新のニュースをGUIで表示します
#!/usr/bin/env bash
# shellcheck disable=SC2034
set -Eeu
#ArchNewsRSSURL="https://www.archlinux.jp/feeds/news.xml"
ArchNewsRSSURL="https://archlinux.org/feeds/news/"
CachePath="${XDG_STATE_HOME-"$HOME/.local/state"}/archnews.latest"
AutoStartPath="${XDG_CONFIG_HOME-"${HOME}/.config"}/autostart/archnews.desktop"
RSSXML=()