~aritra1911/dotfiles

fc88950bb5ee98276d79840371f20548c8312cb3 — Aritra Sarkar 2 years ago 8ce6a75 master
Add scripts
A dotfiles/.scripts/change_wall => dotfiles/.scripts/change_wall +51 -0
@@ 0,0 1,51 @@
#!/usr/bin/sh

PICTURES_DIR="$HOME/pictures"
FEMININE_WALLPAPER_DIR="$PICTURES_DIR/feminine_wallpapers"
NORMAL_WALLPAPER_DIR="$PICTURES_DIR/wallpapers"
WALLPAPER_PREFIX="wallpaper_"
SETROOT_FLAGS="--zoom"

get_random_wallpaper() {
    # first argument is the wallpaper directory
    wallpaper=$(find "$1"/${WALLPAPER_PREFIX}* -type f | shuf -n 1)
}

set_wallpaper() {
    # first argument is path to wallpaper
    setroot $SETROOT_FLAGS "$1"
}

get_and_set_random_wallpaper() {
    # first argument is the wallpaper directory
    get_random_wallpaper "$1"
    set_wallpaper "$wallpaper"
}

reset_subject() {
    [ -e "$TOGGLE" ] && rm "$TOGGLE"
}

change_wallpaper() {
    if [ -e "$TOGGLE" ]; then
        get_and_set_random_wallpaper "$FEMININE_WALLPAPER_DIR"
    else
        get_and_set_random_wallpaper "$NORMAL_WALLPAPER_DIR"
    fi
}

change_subject() {
    if [ ! -e "$TOGGLE" ]; then
        touch "$TOGGLE"
    else
        rm "$TOGGLE"
    fi
}

if [ "$1" = "init" ]; then
    reset_subject
elif [ "$1" = "toggle" ]; then
    change_subject
fi

change_wallpaper

A dotfiles/.scripts/dwm_status => dotfiles/.scripts/dwm_status +86 -0
@@ 0,0 1,86 @@
#!/usr/bin/sh

PADDING=" "
#SEP="|"
#DSEP=" ‖ "
SEP="  "
DSEP=" :: "

get_percentage_used() {
    percentage="$(df -h | grep "$1" | awk '{ print $5 }')"
}

get_storage_status() {
    get_percentage_used "/dev/sda1"
    storage_status="/ $percentage${SEP}"
    get_percentage_used "/dev/sda2"
    storage_status="${storage_status}~ $percentage"
}

get_mem_usage() {
    #https://www.linuxquestions.org/questions/linux-general-1/awk-to-convert-bytes-to-human-number-909214/
    mem_usage=" $(free | awk 'FNR==2{
        split( "K M G" , v );
        p=( $3 * 100 / $2 );
        s=1;
        while ( $3>=1024 ) {
            $3 /= 1024;
            s++;
        }
        if ( s>2 ) {
            printf "%.1f%c (%.0f%%)", $3, v[s], p
        } else {
            printf "%.0f%c (%.0f%%)", $3, v[s], p
        }
    }')"
}

get_temp_core() {
    temperature="$(sensors | grep "Core $1" | awk '{ print $3 }')"
}

get_temperature_status() {
    get_temp_core "0"
    temperature_status="󰍛 $temperature${SEP}"
    get_temp_core "1"
    temperature_status="${temperature_status}󰍛 $temperature"
}

get_volume() {
    if pamixer --get-mute >> /dev/null; then
        volume_icon="󰝟"
    elif [ "$(pamixer --get-volume)" -le "50" ]; then
        volume_icon=""
    else
        volume_icon=""
    fi

    volume_status="$volume_icon $(pamixer --get-volume-human)"
}

get_status_line() {
    # storage
    get_storage_status
    status_line="${PADDING}${storage_status}"

    # memory
    get_mem_usage
    status_line="${status_line}${DSEP}${mem_usage}"

    # temperature
    get_temperature_status
    status_line="${status_line}${DSEP}${temperature_status}"

    # volume
    get_volume
    status_line="${status_line}${DSEP}${volume_status}"

    # date
    status_line="${status_line}${DSEP} $(date '+%a, %b %d')"

    # time
    status_line="${status_line}${DSEP} $(date +%H:%M)${PADDING}"
}

get_status_line
xsetroot -name "$status_line"

A dotfiles/.scripts/mosh_master_man.sh => dotfiles/.scripts/mosh_master_man.sh +73 -0
@@ 0,0 1,73 @@
#!/usr/bin/env bash
#
# Edited and abbreviated version of "ANSI code generator"
#
# © Copyright 2015 Tyler Akins
# Licensed under the MIT license with an additional non-advertising clause
# See http://github.com/fidian/ansi

color-table() {
    local FNB_LOWER FNB_UPPER PADDED

    FNB_LOWER="$(colorize 2 22 f)n$(colorize 1 22 b)"
    FNB_UPPER="$(colorize 2 22 F)N$(colorize 1 22 B)"
    echo -n "bold $(colorize 1 22 Sample)               "
    echo -n "faint $(colorize 2 22 Sample)              "
    echo "italic $(colorize 3 23 Sample)"
    echo -n "underline $(colorize 4 24 Sample)          "
    echo -n "blink $(colorize 5 25 Sample)              "
    echo "inverse $(colorize 7 27 Sample)"
    echo "invisible $(colorize 8 28 Sample)"
    echo -n "strike $(colorize 9 29 Sample)             "
    echo -n "fraktur $(colorize 20 23 Sample)            "
    echo "double-underline $(colorize 21 24 Sample)"
    echo -n "frame $(colorize 51 54 Sample)              "
    echo -n "encircle $(colorize 52 54 Sample)           "
    echo "overline $(colorize 53 55 Sample)"
    echo ""
    echo "             black   red     green   yellow  blue    magenta cyan    white"
    for BG in 40:black 41:red 42:green 43:yellow 44:blue 45:magenta 46:cyan 47:white; do
        PADDED="bg-${BG:3}           "
        PADDED="${PADDED:0:13}"
        echo -n "$PADDED"
        for FG in 30 31 32 33 34 35 36 37; do
            echo -n "$CSI${BG:0:2};${FG}m"
            echo -n "$FNB_LOWER"
            echo -n "$CSI$(( $FG + 60 ))m"
            echo -n "$FNB_UPPER"
            echo -n "${CSI}0m  "
        done
        echo ""
        echo -n "  +intense   "
        for FG in 30 31 32 33 34 35 36 37; do
            echo -n "$CSI$(( ${BG:0:2} + 60 ));${FG}m"
            echo -n "$FNB_LOWER"
            echo -n "$CSI$(( $FG + 60 ))m"
            echo -n "$FNB_UPPER"
            echo -n "${CSI}0m  "
        done
        echo ""
    done
    echo ""
    echo "Legend:"
    echo "    Normal color:  f = faint, n = normal, b = bold."
    echo "    Intense color:  F = faint, N = normal, B = bold."
}

colorize() {
    echo -n "$CSI${1}m$3$CSI${2}m"
}

# Handle long options until we hit an unrecognized thing
CONTINUE=true
RESTORE=true
NEWLINE=false
ESCAPE=false
ESC="$(echo -e '\033')"
CSI="${ESC}["
OSC="${ESC}]"
ST="${ESC}\\"
OUTPUT=""
SUFFIX=""

color-table

A dotfiles/.scripts/query_twitch.py => dotfiles/.scripts/query_twitch.py +58 -0
@@ 0,0 1,58 @@
#!/usr/bin/env python3
import requests
import re
import json
import time

users = [
    "tsoding",
    "lastmiles",
    "enceladosaurus",
    "rwxrob",
    "beginbot",
    "baldengineer",
    "juliestrator",
]

s = requests.session()

homepage = s.get("https://www.twitch.tv").text
client_id = re.search('"Client-ID" ?: ?"(.*?)"', homepage).group(1)

payload = []

for username in users:
    gql_query = 'query{user(login:"USERNAME"){login stream{type}}}'
    payload.append({"query": gql_query.replace("USERNAME", username)})

resp = s.post(
    "https://gql.twitch.tv/gql",
    data=json.dumps(payload),
    headers={"Client-ID": client_id},
).json()
ts = int(time.time())

i = 0  # User index

for stream in resp:
    if not stream["data"]["user"]:
        print(f"{ts} \033[31;7mError : \033[31;1;7m" + users[i] + "\033[0;31;7m was not found!\033[0m")
        i += 1
        continue

    username = stream["data"]["user"]["login"]
    online = stream["data"]["user"]["stream"] is not None

    if online:
        ts_hl = '\033[33m'
        username_hl = '\033[31;1m'
        status_hl = '\033[32;1;7m'
        end_hl = '\033[0m'
    else:
        ts_hl = ''
        username_hl = ''
        status_hl = ''
        end_hl = ''

    print(f"{ts_hl}{ts} {username_hl}{username} {status_hl}{online}{end_hl}")
    i += 1

A dotfiles/.scripts/reflector.sh => dotfiles/.scripts/reflector.sh +2 -0
@@ 0,0 1,2 @@
#!/usr/bin/sh
sudo reflector --verbose --latest 6 --age 24 --protocol https --protocol http --sort rate --save /etc/pacman.d/mirrorlist

A dotfiles/.scripts/screenshot => dotfiles/.scripts/screenshot +2 -0
@@ 0,0 1,2 @@
#!/usr/bin/sh
scrot "/home/ray/pictures/screenshots/%s_%H%M_%d.%m.%Y_\$wx\$h.png" --quality 100

M stage.sh => stage.sh +6 -0
@@ 36,3 36,9 @@ NVIM_INIT_VIM="init.vim"
mkdir -p "$DOTFILES_CONFIG_DIR/$NVIM_INIT_VIM_DIR"
cp  "$XDG_CONFIG_HOME/$NVIM_INIT_VIM_DIR/$NVIM_INIT_VIM" \
    "$DOTFILES_CONFIG_DIR/$NVIM_INIT_VIM_DIR/$NVIM_INIT_VIM"

# Scripts
SCRIPTS_DIR=".scripts"
mkdir -p "$DOTFILES_HOME_DIR/$SCRIPTS_DIR"
cp  "$HOME/$SCRIPTS_DIR"/* \
    "$DOTFILES_HOME_DIR/$SCRIPTS_DIR"