feat: redesign the project structure

This commit is contained in:
ryan4yin
2023-05-26 19:25:44 +08:00
parent ab11958597
commit f971ec030d
124 changed files with 711 additions and 540 deletions

View File

@@ -0,0 +1,54 @@
#!/usr/bin/env bash
## Script To Manage Brightness For Archcraft (in Wayland).
iDIR="$HOME/.config/hypr/mako/icons"
# Get brightness
get_backlight() {
LIGHT=$(printf "%.0f\n" $(light -G))
echo "${LIGHT}%"
}
# Get icons
get_icon() {
backlight="$(get_backlight)"
current="${backlight%%%}"
if [[ ("$current" -ge "0") && ("$current" -le "20") ]]; then
icon="$iDIR/brightness-20.png"
elif [[ ("$current" -ge "20") && ("$current" -le "40") ]]; then
icon="$iDIR/brightness-40.png"
elif [[ ("$current" -ge "40") && ("$current" -le "60") ]]; then
icon="$iDIR/brightness-60.png"
elif [[ ("$current" -ge "60") && ("$current" -le "80") ]]; then
icon="$iDIR/brightness-80.png"
elif [[ ("$current" -ge "80") && ("$current" -le "100") ]]; then
icon="$iDIR/brightness-100.png"
fi
}
# Notify
notify_user() {
notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "Brightness : $(get_backlight)"
}
# Increase brightness
inc_backlight() {
light -A 5 && get_icon && notify_user
}
# Decrease brightness
dec_backlight() {
light -U 5 && get_icon && notify_user
}
# Execute accordingly
if [[ "$1" == "--get" ]]; then
get_backlight
elif [[ "$1" == "--inc" ]]; then
inc_backlight
elif [[ "$1" == "--dec" ]]; then
dec_backlight
else
get_backlight
fi

View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
## Simple Script To Pick Color Quickly.
color=$(grim -g "$(slurp -b 1B1F2800 -p)" -t ppm - | convert - -format '%[pixel:p{0,0}]' txt:- | tail -n1 | cut -d' ' -f4)
image=/tmp/${color}.png
main() {
if [[ "$color" ]]; then
# copy color code to clipboard
echo $color | tr -d "\n" | wl-copy
# generate preview
convert -size 48x48 xc:"$color" ${image}
# notify about it
notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i ${image} "$color, copied to clipboard."
fi
}
# Run the script
main

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# Times the screen off and puts it to background
swayidle \
timeout 300 'swaymsg "output * power off"' \
resume 'swaymsg "output * power on"' &
# Locks the screen immediately
swaylock
# Kills last background task so idle timer doesn't keep running
kill %%

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env bash
## launch wofi with alt config
CONFIG="$HOME/.config/hypr/wofi/config"
STYLE="$HOME/.config/hypr/wofi/style.css"
COLORS="$HOME/.config/hypr/wofi/colors"
if [[ ! $(pidof wofi) ]]; then
wofi --show drun --prompt 'Search...' --conf ${CONFIG} --style ${STYLE} --color ${COLORS}
else
pkill wofi
fi

View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
## launch mako with alt config
CONFIG="$HOME/.config/hypr/mako/config"
if [[ ! $(pidof mako) ]]; then
mako --config ${CONFIG}
fi

View File

@@ -0,0 +1,55 @@
#!/usr/bin/env bash
## Script to take screenshots with grim, slurp (in Wayland)
iDIR="$HOME/.config/hypr/mako/icons"
time=$(date +%Y-%m-%d-%H-%M-%S)
dir="$(xdg-user-dir PICTURES)/Screenshots" # need
file="Screenshot_${time}_${RANDOM}.png"
# notify and view screenshot
notify_cmd_shot="notify-send -h string:x-canonical-private-synchronous:shot-notify -u low -i ${iDIR}/picture.png"
notify_view () {
${notify_cmd_shot} "Copied to clipboard."
imv ${dir}/"$file"
if [[ -e "$dir/$file" ]]; then
${notify_cmd_shot} "Screenshot Saved."
else
${notify_cmd_shot} "Screenshot Deleted."
fi
}
# take shots
shotnow () {
cd ${dir} && grim - | tee "$file" | wl-copy
notify_view
}
shotwin () {
w_pos=$(hyprctl activewindow | grep 'at:' | cut -d':' -f2 | tr -d ' ' | tail -n1)
w_size=$(hyprctl activewindow | grep 'size:' | cut -d':' -f2 | tr -d ' ' | tail -n1 | sed s/,/x/g)
cd ${dir} && grim -g "$w_pos $w_size" - | tee "$file" | wl-copy
notify_view
}
shotarea () {
cd ${dir} && grim -g "$(slurp -b 1B1F28CC -c E06B74ff -s C778DD0D -w 2)" - | tee "$file" | wl-copy
notify_view
}
if [[ ! -d "$dir" ]]; then
mkdir -p "$dir"
fi
if [[ "$1" == "--now" ]]; then
shotnow
elif [[ "$1" == "--area" ]]; then
shotarea
elif [[ "$1" == "--win" ]]; then
shotwin
else
echo -e "Available Options : --now --win --area"
fi
exit 0

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
## Autostart Programs
# Kill already running process
_ps=(waybar mako mpd)
for _prs in "${_ps[@]}"; do
if [[ $(pidof ${_prs}) ]]; then
killall -9 ${_prs}
fi
done
# Set wallpaper
swaybg --output '*' --mode fill --image ~/.config/hypr/wallpapers/wallpaper.png &
# Lauch notification daemon (mako)
~/.config/hypr/scripts/notifications &
# Lauch statusbar (waybar)
~/.config/hypr/scripts/statusbar &
# Start mpd
exec mpd &

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
## launch waybar with alt config
CONFIG="$HOME/.config/hypr/waybar/config"
STYLE="$HOME/.config/hypr/waybar/style.css"
if [[ ! $(pidof waybar) ]]; then
waybar --bar main-bar --log-level error --config ${CONFIG} --style ${STYLE}
fi

View File

@@ -0,0 +1,76 @@
#!/usr/bin/env bash
## Script To Manage Speaker Volume For Archcraft (in Wayland).
iDIR="$HOME/.config/hypr/mako/icons"
# Get Volume
get_volume() {
volume=$(amixer get Master | tail -n1 | awk -F ' ' '{print $5}' | tr -d '[]')
echo "$volume"
}
# Get icons
get_icon() {
vol="$(get_volume)"
current="${vol%%%}"
if [[ "$current" -eq "0" ]]; then
icon="$iDIR/volume-mute.png"
elif [[ ("$current" -ge "0") && ("$current" -le "30") ]]; then
icon="$iDIR/volume-low.png"
elif [[ ("$current" -ge "30") && ("$current" -le "60") ]]; then
icon="$iDIR/volume-mid.png"
elif [[ ("$current" -ge "60") && ("$current" -le "100") ]]; then
icon="$iDIR/volume-high.png"
fi
}
# Notify
notify_user() {
notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "Volume : $(get_volume)"
}
# Increase Volume
inc_volume() {
amixer -Mq set Master,0 5%+ unmute && get_icon && notify_user
}
# Decrease Volume
dec_volume() {
amixer -Mq set Master,0 5%- unmute && get_icon && notify_user
}
# Toggle Mute
toggle_mute() {
amixer get Master | grep '\[on\]' &>/dev/null
if [[ "$?" == 0 ]]; then
amixer set Master toggle && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$iDIR/volume-mute.png" "Mute"
else
amixer set Master toggle && get_icon && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "Unmute"
fi
}
# Toggle Mic
toggle_mic() {
amixer get Capture | grep '\[on\]' &>/dev/null
if [[ "$?" == 0 ]]; then
amixer -D pulse sset Capture toggle && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$iDIR/microphone-mute.png" "Microphone Switched OFF"
else
amixer -D pulse sset Capture toggle && get_icon && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$iDIR/microphone.png" "Microphone Switched ON"
fi
}
# Execute accordingly
if [[ "$1" == "--get" ]]; then
get_volume
elif [[ "$1" == "--inc" ]]; then
inc_volume
elif [[ "$1" == "--dec" ]]; then
dec_volume
elif [[ "$1" == "--toggle" ]]; then
toggle_mute
elif [[ "$1" == "--toggle-mic" ]]; then
toggle_mic
else
get_volume
fi

View File

@@ -0,0 +1,120 @@
#!/usr/bin/env python
import subprocess
from pyquery import PyQuery # install using `pip install pyquery`
import json
# weather icons
weather_icons = {
"sunnyDay": "滛",
"clearNight": "望",
"cloudyFoggyDay": "",
"cloudyFoggyNight": "",
"rainyDay": "",
"rainyNight": "",
"snowyIcyDay": "",
"snowyIcyNight": "",
"severe": "",
"default": "",
}
# get location_id
# to get your own location_id, go to https://weather.com & search your location.
# once you choose your location, you can see the location_id in the URL(64 chars long hex string)
# Shenzen, Guangdong's location id: https://weather.com/en-IN/weather/today/l/7a4684e0789c881e79935986f2e9e5ab05b0104ac4310fd8818006dfb66092c3
location_id = "7a4684e0789c881e79935986f2e9e5ab05b0104ac4310fd8818006dfb66092c3"
# get html page
url = "https://weather.com/en-IN/weather/today/l/" + location_id
html_data = PyQuery(url=url)
# current temperature
temp = html_data("span[data-testid='TemperatureValue']").eq(0).text()
# print(temp)
# current status phrase
status = html_data("div[data-testid='wxPhrase']").text()
status = f"{status[:16]}.." if len(status) > 17 else status
# print(status)
# status code
status_code = html_data("#regionHeader").attr("class").split(" ")[2].split("-")[2]
# print(status_code)
# status icon
icon = (
weather_icons[status_code]
if status_code in weather_icons
else weather_icons["default"]
)
# print(icon)
# temperature feels like
temp_feel = html_data(
"div[data-testid='FeelsLikeSection'] > span[data-testid='TemperatureValue']"
).text()
temp_feel_text = f"Feels like {temp_feel}c"
# print(temp_feel_text)
# min-max temperature
temp_min = (
html_data("div[data-testid='wxData'] > span[data-testid='TemperatureValue']")
.eq(0)
.text()
)
temp_max = (
html_data("div[data-testid='wxData'] > span[data-testid='TemperatureValue']")
.eq(1)
.text()
)
temp_min_max = f" {temp_min}\t\t {temp_max}"
# print(temp_min_max)
# wind speed
wind_speed = html_data("span[data-testid='Wind']").text().split("\n")[1]
wind_text = f"煮 {wind_speed}"
# print(wind_text)
# humidity
humidity = html_data("span[data-testid='PercentageValue']").text()
humidity_text = f" {humidity}"
# print(humidity_text)
# visibility
visbility = html_data("span[data-testid='VisibilityValue']").text()
visbility_text = f" {visbility}"
# print(visbility_text)
# air quality index
air_quality_index = html_data("text[data-testid='DonutChartValue']").text()
# print(air_quality_index)
# hourly rain prediction
prediction = html_data("section[aria-label='Hourly Forecast']")(
"div[data-testid='SegmentPrecipPercentage'] > span"
).text()
prediction = prediction.replace("Chance of Rain", "")
prediction = f"\n\n  (hourly) {prediction}" if len(prediction) > 0 else prediction
# print(prediction)
# tooltip text
tooltip_text = str.format(
"\t\t{}\t\t\n{}\n{}\n{}\n\n{}\n{}\n{}{}",
f'<span size="xx-large">{temp}</span>',
f"<big>{icon}</big>",
f"<big>{status}</big>",
f"<small>{temp_feel_text}</small>",
f"<big>{temp_min_max}</big>",
f"{wind_text}\t{humidity_text}",
f"{visbility_text}\tAQI {air_quality_index}",
f"<i>{prediction}</i>",
)
# print waybar module data
out_data = {
"text": f"{icon} {temp}",
"alt": status,
"tooltip": tooltip_text,
"class": status_code,
}
print(json.dumps(out_data))

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
## wlogout with alt layout and style file
LAYOUT="$HOME/.config/hypr/wlogout/layout"
STYLE="$HOME/.config/hypr/wlogout/style.css"
if [[ ! $(pidof wlogout) ]]; then
wlogout --layout ${LAYOUT} --css ${STYLE} \
--column-spacing 20 \
--row-spacing 20 \
--margin-top 200 \
--margin-bottom 200 \
--margin-left 150 \
--margin-right 150
else
pkill wlogout
fi