From 4771f87d66e38a2a37feec0b4b16aba953fb3076 Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 1 Feb 2021 18:02:21 -0500 Subject: [PATCH] Add picker and music downloader --- README.md | 2 +- dwm-start | 4 +-- mru | 2 +- prompt | 73 ++++++++++++++++++++++++++++++++++++++++--------------- 4 files changed, 58 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 4d5edeb..25931b5 100644 --- a/README.md +++ b/README.md @@ -109,5 +109,5 @@ what?- Consider entr in dwm-start for watching files - unicode character insertion - finish editing text-opener change prompt icon to nerd icon -- select window with wmctrl +- finish dwm patching, select window with wmctrl, then setup vpn, then maybe dmenu patches - prompt for copying files to laptop diff --git a/dwm-start b/dwm-start index be2b8fb..bc7e216 100755 --- a/dwm-start +++ b/dwm-start @@ -2,8 +2,8 @@ setxkbmap -option caps:swapescape picom -b ~/.fehbg -xbindkeys -f $HOME/Backups/configs/xbindkeysrc -mru update & +xbindkeys -f $HOME/backups/configs/xbindkeysrc +( mru update; mru updatedirs ) & # relaunch DWM if the binary changes, otherwise bail csum=$(sha1sum $(which dwm.winkey)) diff --git a/mru b/mru index 7cc2aad..de2709c 100755 --- a/mru +++ b/mru @@ -26,7 +26,7 @@ create_new() { path=$(get_cache_path "$1") find $path -type f -not \( -path '*/.*/*' -o -path '*node_modules/*' -o \ - -path '*Backups/my-plugins*' -o -path '*.sw[po]' \) -printf \ + -path '*backups/my-plugins*' -o -path '*.sw[po]' \) -printf \ '%TY-%Tm-%Td\t%TT\t%p\n' | sort -r > $file'.new' } diff --git a/prompt b/prompt index e0bdfe4..d864d06 100755 --- a/prompt +++ b/prompt @@ -9,6 +9,8 @@ launch() { Edit Editor Open + Pick + Choose Terminal Multiplexer LBRY @@ -26,11 +28,13 @@ launch() { dmenu -i -p "Launcher") case $app in - Notes) st -t "Notes" -e vim "+cd ~/Notes/text" "+CtrlP";; + Notes) st -t "Notes" -e vim "+cd ~/notes/text" "+CtrlP";; Files) st -t "Files" -e sh -lc nnn;; Edit) editor;; Editor) st -t "Editor" -e vim "+CtrlPMRUFiles";; Open) opener;; + Pick) pick;; + Choose) choose;; Terminal) st -t "Terminal";; Page) pages pager "$(printf "1\n2\n3\n" | dmenu -p 'page')";; Multiplexer) st -t "Multiplexer" -e tmux attach-session -t 0 || st -t "Multiplexer" -e tmux new-session -s 0;; @@ -42,7 +46,7 @@ launch() { 'Hidden browser') $browser_cmd --incognito;; Email) $browser_cmd mail.protonmail.com/login;; 'Play clipboard') mpv "$(xclip -o -selection clipboard)";; - 'Play downloads') mpv "$HOME/Downloads/tmp/$(ls ~/Downloads/tmp/ | dmenu -i -l 10 -p 'play')";; + 'Play downloads') mpv "$HOME/downloads/tmp/$(ls ~/downloads/tmp/ | dmenu -i -l 10 -p 'play')";; Processes) st -t "Processes" -e htop;; esac } @@ -53,8 +57,6 @@ action() { Play Music Command Command to clipboard - Choose - Choosedir Select VPN Disable VPN Enable VPN @@ -66,6 +68,8 @@ action() { Username Alternate password Download + Download music + Update cache Enable Bar" | tr -d '\t' | dmenu -i -p "Actions") @@ -77,15 +81,15 @@ action() { 'Disable Bar') tmux set -g status off;; 'Enable Bar') tmux set -g status on;; 'Command') cmd;; - 'Choose') chooser;; - 'Choosedir') choosedir;; 'Command to clipboard') cmd_clip;; 'Username') username;; 'Password') password;; 'Alternate password') other_password;; 'Show calender') notify-send 'Calender' "\n\n$(cal)";; + 'Update cache') { mru update; mru updatedirs; };; #This should check for an error code and confirm that download has started - 'Download') youtube-dl --no-progress -o "$HOME/Downloads/tmp/%(title)s.%(ext)s" "$(xclip -selection clipboard -o)"; notify-send -u low -t 3000 "Download complete";; + 'Download') download;; + 'Download music') download_music;; esac } @@ -104,6 +108,7 @@ login() { Show) show_password;; esac } + do_search() { type=$(printf "Manual DDG @@ -114,7 +119,7 @@ do_search() { Github" | tr -d '\t' | dmenu -i -p "Search") case "$type" in - Manual) p=$(printf '' | dmenu -p 'man'); if [ -z $p ]; then exit; fi; st -t "Manual $p" -e man "$p";; + Manual) p=$(man -k '' | dmenu -l 20 -p 'Manual' | cut -d' ' -f1); if [ -z $p ]; then exit; fi; st -t "Manual - $p" -e man "$p";; Github) github;; Godocs) godoc;; DDG) ddg;; @@ -123,6 +128,20 @@ do_search() { esac } +download() { +youtube-dl --no-progress -o "$HOME/downloads/%(title)s.%(ext)s" "$(xclip -selection clipboard -o)" +notify-send -u low -t 3000 "Download complete" +} +download_music() { + youtube-dl --no-progress -f bestaudio -o \ + "$HOME/downloads/music/%(track)s - %(artist)s.%(ext)s" "$(xclip -selection clipboard -o)" + if [ $? ]; then + youtube-dl --no-progress -f bestaudio -o \ + "$HOME/downloads/music/%(title)s - %(artist)s.%(ext)s" "$(xclip -selection clipboard -o)" + fi + notify-send -u low -t 3000 "Download complete" + +} package() { type=$(printf "search\ninfo" | dmenu -p 'package') if [ -z "$type" ]; then @@ -326,35 +345,51 @@ edit_password() { if [ -n "$error" ]; then notify-send -u low -t 3000 "password edit error" "$error"; fi } -chooser() { - f=$(mru list | dmenu -i -l 20 -p 'choose file') +# Execute a command with the specified file or directory as it's argument +choose() { + d=$(mru listdirs | dmenu -i -l 20 -p 'from') + if [ -z "$d" ]; then exit; fi + f=$( + (printf "$d\n"; find "$d" -type f -not \( -path '*/.*/*' -o -path '*node_modules/*' -o -ipath '*backups/my-plugins*' -o -ipath '*/.uuid' -ipath '*.swp*' \)) | + dmenu -i -l 20 -p 'choose file' + ) if [ -z "$f" ]; then exit; fi - c=$(dmenu_path | dmenu -i -p 'operation') - if [ -z $c ]; then exit; fi - $c "$f" -} -choosedir(){ - f=$(mru listdirs | dmenu -i -l 20 -p 'choose dir') - if [ -z "$f" ]; then exit; fi c=$(dmenu_path | dmenu -i -p 'operation') if [ -z $c ]; then exit; fi $c "$f" -} +} vpn() { ls } +# It finds all the current files in a known directory without needing to update the mru list of files +# If the directory is chosen instead of the file within it, it opens the directory with nnn +pick() { + d=$(mru listdirs | dmenu -i -l 20 -p 'from') + if [ -z "$d" ]; then exit; fi + f=$( + (printf "$d\n"; find "$d" -type f -not \( -path '*/.*/*' -o -path '*node_modules/*' -o -ipath '*backups/my-plugins*' -o -ipath '*/.uuid' -ipath '*.swp*' \)) | + dmenu -i -l 20 -p 'pick file' + ) + if [ -z "$f" ]; then exit; fi + if [ "$d" = "$f" ]; then st -t 'Files' -e sh -lc "nnn '$f'"; exit; fi + xdg-open "$f" +} + case $1 in launch ) launch;; action) action;; + pick) pick;; cmd) cmd;; cmd_clip) cmd_clip;; login) login;; search) do_search;; open) opener;; - choose) chooser;; + choose) choose;; vpn) vpn;; + download) download;; + download_music) download_music;; *) printf "Invalid argument";; esac