summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xautolocker.sh17
-rwxr-xr-xdockd.sh54
-rwxr-xr-xtoggle-docked.sh26
-rwxr-xr-xurl_handler.sh10
-rwxr-xr-xyt.sh67
5 files changed, 69 insertions, 105 deletions
diff --git a/autolocker.sh b/autolocker.sh
deleted file mode 100755
index 692fbfb..0000000
--- a/autolocker.sh
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-
-if [ "$1" = "-d" ]; then
- xautolock \
- -notify 10 \
- -time 10 \
- -locker "i3lock -n -f -c 000000 -i ~/.local/share/wallpapers/lock.png; sleep 0.2" \
- -notifier "notify-send -t=10000 '10 seconds to lock...'"
-else
- xautolock \
- -killtime 10 \
- -killer "sleep 0.5; doas acpiconf -s3" \
- -notify 10 \
- -time 10 \
- -locker "i3lock -n -f -c 000000 -i ~/.local/share/wallpapers/lock.png; sleep 0.2" \
- -notifier "notify-send -t=10000 '10 seconds to lock...'"
-fi
diff --git a/dockd.sh b/dockd.sh
new file mode 100755
index 0000000..235035a
--- /dev/null
+++ b/dockd.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+dock() {
+ echo Docking...
+ xrandr \
+ --output DP-0 --off \
+ --output DP-1 --off \
+ --output DP-2 --primary --mode 2560x1440 --pos 0x0 --rotate normal --dpi 96 \
+ --output DP-3 --off \
+ --output DP-4 --off \
+ --output VGA-0 --off
+ killall xautolock
+ xautolock \
+ -notify 10 \
+ -time 10 \
+ -locker "i3lock -n -f -c 000000 -i ~/.local/share/wallpapers/lock.png; sleep 0.2" \
+ -notifier "notify-send -t=10000 '10 seconds to lock...'"
+ sysctl hw.snd.default_unit=1
+ echo Docked
+}
+
+undock() {
+ echo Undocking...
+ xrandr \
+ --output DP-0 --off \
+ --output DP-1 --off \
+ --output DP-2 --off \
+ --output DP-3 --primary --mode 1920x1080 --transform none --pos 0x0 --rotate normal --dpi 96 \
+ --output DP-4 --off \
+ --output VGA-0 --off
+ killall xautolock
+ xautolock \
+ -killtime 10 \
+ -killer "sleep 0.5; doas acpiconf -s3" \
+ -notify 10 \
+ -time 10 \
+ -locker "i3lock -n -f -c 000000 -i ~/.local/share/wallpapers/lock.png; sleep 0.2" \
+ -notifier "notify-send -t=10000 '10 seconds to lock...'"
+ sysctl hw.snd.default_unit=4
+ echo Undocked
+}
+
+while :
+do
+ is_lid_open=$(sysctl -n dev.acpi_lid.0.state)
+
+ if [ "$is_lid_open" != "$was_lid_open" ]
+ then
+ was_lid_open=$is_lid_open
+ [ "$is_lid_open" = "0" ] && dock || undock
+ fi
+
+ sleep 10
+done
diff --git a/toggle-docked.sh b/toggle-docked.sh
deleted file mode 100755
index a04540e..0000000
--- a/toggle-docked.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/sh
-big=2560x1440
-little=1920x1080
-is_docked=$(xrandr | grep DP-2 | cut -w -f2)
-
-if [ "$is_docked" = "connected" ]; then
- xrandr \
- --output DP-0 --off \
- --output DP-1 --off \
- --output DP-2 --primary --mode $big --pos 0x0 --rotate normal \
- --output DP-3 --scale-from $big --same-as DP-2 --rotate normal \
- --output DP-4 --off \
- --output VGA-0 --off \
- && killall xautolock
- autolocker.sh -d &
-else
- xrandr \
- --output DP-0 --off \
- --output DP-1 --off \
- --output DP-2 --off \
- --output DP-3 --primary --mode $little --transform none --pos 0x0 --rotate normal \
- --output DP-4 --off \
- --output VGA-0 --off \
- && killall xautolock
- autolocker.sh &
-fi
diff --git a/url_handler.sh b/url_handler.sh
new file mode 100755
index 0000000..931fce6
--- /dev/null
+++ b/url_handler.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+echo $1
+
+case $1 in
+ *youtube.com*) yt.sh $1 ;;
+ *youtu.be*) yt.sh $1 ;;
+ *mailto*) echo Mail ;;
+ *) $BROWSER $1 ;;
+esac
+
diff --git a/yt.sh b/yt.sh
index 8fcf8c5..f270bc6 100755
--- a/yt.sh
+++ b/yt.sh
@@ -3,8 +3,6 @@
## Config:
TERMINAL=alacritty
DOWNLOAD_DIR=~/videos/youtube
-PAGER="rofi -location 2 -width 41 -e"
-YOUTUBE_REGEX=".*((https?\:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+)$"
## Exit codes
@@ -19,56 +17,14 @@ get_action_single() {
2. listen in player
3. download video
4. download audio
-5. print info
EOF
)
echo "$action" | cut -d'.' -f1
}
-
-## Get action for multiple URLs
-get_action_multi() {
- # TODO: implement
-}
-
-
-## Check if url is a youtube url
-check_if_youtube() {
- url="$1"
- echo $url | grep -qE "$YOUTUBE_REGEX" && return 0 || return 1
-}
-
-
-## Prompts user for URL
-prompt_url() {
- dmenu -p "YouTube URL"
-}
-
-
-## Grab url from clipboard/primary selection, else get via prompt
-grab_url() {
- if url="$1" && check_if_youtube $url; then
- elif url=$(xclip -o -selection clipboard 2>/dev/null || echo) && check_if_youtube $url; then
- elif url=$(xclip -o 2>/dev/null || echo) && check_if_youtube $url; then
- elif url=$(grab_url_stdin) && check_if_youtube $url; then
- elif url=$(prompt_url) && check_if_youtube $url; then
- else
- exit $NO_YOUTUBE_URL
- fi
-
- echo $url
-}
-
-
-## Extract URL from stdin
-grab_url_stdin() {
- sed -nE "s/$YOUTUBE_REGEX/\1/p"
-}
-
-
## Get title, description, and duration of URL
get_info() {
- url="$1"
+ url=$1
info=$(youtube-dl --get-title --get-description --get-duration $url)
title=$(echo "$info" | head -n 1)
description=$(echo "$info" | sed '1d;$d')
@@ -79,7 +35,7 @@ get_info() {
## Download video
download_video() {
- url="$1"
+ url=$1
info=$(get_info $url)
notify-send "Downloading video..." "$info" &
youtube-dl \
@@ -92,7 +48,7 @@ download_video() {
## Download audio
download_audio() {
- url="$1"
+ url=$1
info=$(get_info $url)
notify-send "Downloading audio..." "$info"
youtube-dl \
@@ -108,7 +64,7 @@ download_audio() {
## Play video
play_video() {
- url="$1"
+ url=$1
notify-send "Playing video..." "$(get_info $url)" &
mpv --no-terminal --geometry=25%-10-40 --title="Streaming from YouTube" $url &
}
@@ -116,28 +72,15 @@ play_video() {
## Play audio
play_audio() {
- url="$1"
+ url=$1
notify-send "Playing audio..." "$(get_info $url)" &
$TERMINAL -t "Streaming from YouTube" -e mpv --no-video $url &
}
-
-## Print info with specified pager
-print_info() {
- url="$1"
- info=$(get_info $url)
- $PAGER "$info"
-}
-
-
## Main
mkdir -p "$DOWNLOAD_DIR"
-url=$(grab_url "$1")
case "$(get_action_single)" in
- 5)
- print_info $url
- ;;
1)
play_video $url
;;