Parcourir la source

Finish mru insert and init

master
= il y a 4 ans
Parent
révision
98da93c6b7
5 fichiers modifiés avec 164 ajouts et 69 suppressions
  1. +23
    -16
      README.md
  2. +52
    -7
      mru
  3. +15
    -0
      pinentry
  4. +71
    -46
      prompt
  5. +3
    -0
      text-opener

+ 23
- 16
README.md Voir le fichier

@@ -29,10 +29,7 @@ the source code for more details.
* action * action
* cmd * cmd
* cmd_clip * cmd_clip
* github * search
* godoc
* ddg
* manual
* username * username
* password * password
* other_password * other_password
@@ -40,18 +37,19 @@ the source code for more details.
* open * open
* edit * edit


Generaly, prompt has two types of commands, launch commands and action most functionality is accessible from launch and action only
commands. Launch commands are used to open applications, manual pages, or spawn
other windows. Action commands modify daemons or read/write th the clipboard.
This means that `prompt launch` and `prompt action` are the only important
subcommands because they will prompt for all the rest.


### Notes ### Notes
* The download action uses youtube-dl to download whatever is in the keyboard to ~/Downloads/tmp * The download action uses youtube-dl to download whatever is in the keyboard
to ~/Downloads/tmp
* You may want to bind Mod4+a to `launch action` and Mod4+g to `prompt launch` * You may want to bind Mod4+a to `launch action` and Mod4+g to `prompt launch`
* Some prompts like `search package` will infer with their default operation
when the string entered is an invalid selection


## mru ## mru
Used for indexing and ranking frequently accessed files to ~/.cache/mru Used for storing file paths and their modification times in ~/.cache/mru. It
doesn't actually implement a caching algorithm using hit rate but it may be
added in the future.
mru [COMMAND] [CACHE] mru [COMMAND] [CACHE]


#### COMMMAND #### COMMMAND
@@ -59,8 +57,12 @@ Used for indexing and ranking frequently accessed files to ~/.cache/mru
- update - update
- output - output
- list - list
- insert [ FILE ]

#### Notes
- If no cache is specified, it assumes 'home'
- If if the file passed to insert does not exist, it is removed from the cache


If no cache is specified, it assumes 'home'
### Initializing ### Initializing
mru init; mru create home $HOME all mru init; mru create home $HOME all


@@ -72,7 +74,9 @@ can be created from your own tools. I use it for viewing documentation.
### Usage ### Usage
pages [ pager | pdf | browser | send ] [ NAME ] pages [ pager | pdf | browser | send ] [ NAME ]


send will send stdin to the named page with the naming convention /tmp/pages-{NAME}. All other commands attempt to open the named page if it exists. send will send stdin to the named page with the naming convention
/tmp/pages-{NAME}. All other commands attempt to open the named page if it
exists.


#### Notes #### Notes
* Page names don't have to be numbers, here is an example vim Ex mode command I * Page names don't have to be numbers, here is an example vim Ex mode command I
@@ -84,7 +88,9 @@ daemons, execute arbitrary commands, search the web, grab passwords from the
password manager, and more. password manager, and more.


#### TODO #### TODO
- Finish vpn and networking stuff after ini script is finished, then make sure printf in case goes to stderror which is shown in bar - Finish vpn and networking stuff after ini script is finished, then make sure
- maybe add an mru ranking alrogithm in the future
printf in case goes to stderror which is shown in bar
- Add ddg search prompt - Add ddg search prompt
- setup pass - setup pass
- variables to the script to make assumed paths easier to change - variables to the script to make assumed paths easier to change
@@ -97,5 +103,6 @@ password manager, and more.
- Make password prompts green - Make password prompts green
- Figure out range selecting for parsing passwords - Figure out range selecting for parsing passwords
- Figure out using dmenu instead of gnome key prompt - Figure out using dmenu instead of gnome key prompt
- Consider entr, inotifywait, auditctl, or find -atime for MRU - Consider entr in dwm-start for watching files
- setup xdg-open. Need it for opener and editors - make dmenu load time more like fzf?
- change xdg text/plain opener to use vim and st if not in terminal

+ 52
- 7
mru Voir le fichier

@@ -2,16 +2,33 @@


#To add more caches, add a newline to this string and follow the existing name:path format #To add more caches, add a newline to this string and follow the existing name:path format
cache_info="home:$HOME" cache_info="home:$HOME"
HOME=/home/immanuel
XDG_CACHE_HOME="$HOME/.cache"


init() { init() {
mkdir -p $XDG_CACHE_HOME/mru mkdir -p $XDG_CACHE_HOME/mru
file=$XDG_CACHE_HOME/mru/"$1"
if [ -z "$1" ]; then file="$file""home"; fi
path=$(printf $cache_info | grep "^$1" - | cut -d: -f2)

if [ -z "$path" -o ! -e "$path" ]; then
printf "path:$path from cache:$file does not exist\n" 1>&2; exit;
fi
find $path -type f -not \( -path '*/.*/*' -o -path '*node_modules/*' -o \
-path '*Backups/my-plugins*' -o -path '*.sw[po]' \) -printf \
'%TY-%Tm-%Td\t%TT\t%p\n' | sort -r > $file'.new'
mv "$file.new" "$file"
} }


get_cache_path() { get_cache_path() {
if [ -z "$1" ]; then printf "invalid arg to cache_path\n"; exit; fi if [ -z "$1" ]; then printf "no arg to get_cache_path\n" 1>&2; exit; fi
path="$(printf $cache_info | grep "^$1" - | cut -d: -f2)"
if [ -z "$path" ]; then printf "invalid cache name: $1\n" 1>&2; exit; fi
printf "$path"
} }


update() { update() {
clean
file=$XDG_CACHE_HOME/mru/"$1" file=$XDG_CACHE_HOME/mru/"$1"
if [ -z "$1" ]; then file="$file""home"; fi if [ -z "$1" ]; then file="$file""home"; fi
path=$(printf $cache_info | grep "^$1" - | cut -d: -f2) path=$(printf $cache_info | grep "^$1" - | cut -d: -f2)
@@ -19,14 +36,18 @@ update() {
if [ -z "$path" -o ! -e "$path" ]; then if [ -z "$path" -o ! -e "$path" ]; then
printf "path:$path from cache:$file does not exist\n"; exit; printf "path:$path from cache:$file does not exist\n"; exit;
fi fi
find $path -type f -not \( -path '*/.*/*' -o -path '*node_modules/*' -o \ #init a temporary file. The traverse the original, if a file exists in a
-path '*Backups/my-plugins*' -o -path '*.sw[po]' \) -printf \ # but not in b, delete it from a, if it exists in a and b delete it from b.
'%TY-%Tm-%Td\t%TT\t%p\n' | sort -r > $file # append the rest of b to a.
# This should check if each file found is already there. If not, add it to it's position based on modified time
# find $path -type f -not \( -path '*/.*/*' -o -path '*node_modules/*' -o \
# -path '*Backups/my-plugins*' -o -path '*.sw[po]' \) -printf \
# '%TY-%Tm-%Td\t%TT\t%p\n' | sort -r > $file
} }


output() { output() {
if [ -z "$2" ]; then if [ -z "$1" ]; then
cat $XDG_CACHE_HOME/mru/home; else cat "$XDG_CACHE_HOME/mru/$2"; cat $XDG_CACHE_HOME/mru/home; else cat "$XDG_CACHE_HOME/mru/$1";
fi fi
} }


@@ -34,10 +55,34 @@ list() {
output "$1" | cut -f3 output "$1" | cut -f3
} }


insert() {
if [ -z "$1" ]; then printf "No path given\n" 1>&2; exit; fi
cache_name=${1+'home'}
cache_path=$(get_cache_path "$cache_name")

file_path=$(realpath "$1")
if [ -e "$file_path" ]; then
# sed "0,\|.*\t.*\t$file_path|s|||" $XDG_CACHE_HOME/mru/$cache_name
sed -e "0,\|.*\t.*\t$file_path|s|||" -e "1s;^;$(date '+%Y-%m-%d%t%T')\t$file_path\n;" <$XDG_CACHE_HOME/mru/$cache_name \
>$XDG_CACHE_HOME/mru/$cache_name.insert$$
mv $XDG_CACHE_HOME/mru/$cache_name.insert$$ $XDG_CACHE_HOME/mru/$cache_name
else
sed "0,\|.*\t.*\t$file_path|s|||" <$XDG_CACHE_HOME/mru/$cache_name \
>$XDG_CACHE_HOME/mru/$cache_name.insert$$
mv $XDG_CACHE_HOME/mru/$cache_name.insert$$ $XDG_CACHE_HOME/mru/$cache_name

fi
}

clean() {
rm $XDG_CACHE_HOME/mru/*.{insert,new}*
}

case "$1" in case "$1" in
init) init "$2";; init) init "$2";;
update) update $2;; update) update $2;;
output) output "$2";; output) output "$2";;
list) list "$2";; list) list "$2";;
insert) insert "$2";; insert) insert "$2" "$3";;
clean) clean;;
esac esac

+ 15
- 0
pinentry Voir le fichier

@@ -0,0 +1,15 @@
#!/bin/sh

# echo 'OK Pleased to meet you'

# cat - > /tmp/randomish


while read stdin; do
case $stdin in
*BYE*) break ;;
*SETDESC*) KEYNAME=${stdin#*:%0A%22}; KEYNAME=${KEYNAME%\%22\%0A*}; KEYID=${stdin#*ID }; KEYID=${KEYID%,*}; echo OK ;;
*GETPIN*) echo "D `dmenu -P -p "gpg-agent: $KEYNAME ($KEYID)"`\nOK" ;;
*) echo OK;;
esac
done

+ 71
- 46
prompt Voir le fichier

@@ -8,6 +8,7 @@ launch() {
Files Files
Edit Edit
Editor Editor
Open
Terminal Terminal
Multiplexer Multiplexer
LBRY LBRY
@@ -15,11 +16,10 @@ launch() {
Music Music
Browser Browser
Hidden browser Hidden browser
Manual
Email Email
Page Page
Define Define
Package search Go page
Package info Package info
Play clipboard Play clipboard
Play downloads Play downloads
@@ -30,12 +30,13 @@ launch() {
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;; Files) st -t "Files" -e sh -lc nnn;;
Edit) editor;; Edit) editor;;
Editor) st -t "Editor" -e vim;; Editor) st -t "Editor" -e vim "+CtrlPMRUFiles";;
Open) opener;;
Terminal) st -t "Terminal";; Terminal) st -t "Terminal";;
Page) pages pager "$(printf "1\n2\n3\n" | dmenu -p 'page')";; Page) pages pager "$(printf "1\n2\n3\n" | dmenu -p 'page')";;
Manual) p=$(printf '' | dmenu -p 'man'); st -t "Manual $p" -e man "$p";;
Multiplexer) st -t "Multiplexer" -e tmux attach-session -t 0 || st -t "Multiplexer" -e tmux new-session -s 0;; Multiplexer) st -t "Multiplexer" -e tmux attach-session -t 0 || st -t "Multiplexer" -e tmux new-session -s 0;;
LBRY) lbry;; LBRY) lbry;;
'Go page') num=$(go_page); pages pager $num;;
Chat) element-desktop;; Chat) element-desktop;;
Music) st -t "Music" -e ncmpcpp;; Music) st -t "Music" -e ncmpcpp;;
Browser) $browser_cmd;; Browser) $browser_cmd;;
@@ -43,33 +44,17 @@ launch() {
Email) $browser_cmd mail.protonmail.com/login;; Email) $browser_cmd mail.protonmail.com/login;;
'Play clipboard') mpv "$(xclip -o -selection clipboard)";; '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')";;
'Define') word=$(printf '' | dmenu -p 'word'); st -e sh -lc "dict \"$word\" | less";; Define) word=$(printf '' | dmenu -p 'word'); if [ -z "$word" ]; then exit; fi; st -e sh -lc "dict \"$word\" | less";;
'Package search')s=$(printf '' | dmenu -p 'name'); if [ -z "$s" ]; then exit; fi; st -t "Package $s" -e sh -lc "apt search $s | less";;
'Package info')s=$(printf '' | dmenu -p 'name'); if [ -z "$s" ]; then exit; fi; st -t "Package $s" -e sh -lc "apt show $s | less";;
Processes) st -t "Processes" -e htop;; Processes) st -t "Processes" -e htop;;
esac esac
} }


editor() {
file=$(mru list | dmenu -i -l 10 -p 'edit what?')
st -t 'Editor' -e vim "$file"
}

#Opening all mru files, not just for editing
opener() {
sdfs
}

action() { action() {
action=$(printf "Toggle Music action=$(printf "Toggle Music
Pause Music Pause Music
Play Music Play Music
Go page
Command Command
Command to clipboard Command to clipboard
Search github
Search ddg
Search godoc
Select VPN Select VPN
Disable VPN Disable VPN
Enable VPN Enable VPN
@@ -84,26 +69,67 @@ action() {
Enable Bar" | tr -d '\t' | Enable Bar" | tr -d '\t' |
dmenu -i -p "Actions") dmenu -i -p "Actions")


case $action in case $action in
'Play Music') mpc play ;; 'Play Music') mpc play ;;
'Pause Music') mpc pause ;; 'Pause Music') mpc pause ;;
'Toggle Music') mpc toggle ;; 'Toggle Music') mpc toggle ;;
'Rebind Keys') setup-xbindkeys;; 'Rebind Keys') setup-xbindkeys;;
'Disable Bar') tmux set -g status off;; 'Disable Bar') tmux set -g status off;;
'Enable Bar') tmux set -g status on;; 'Enable Bar') tmux set -g status on;;
'Search github') github;; 'Command') cmd;;
'Search godoc') godoc;; 'Command to clipboard') cmd_clip;;
'Search ddg') ddg;; 'Username') username;;
'Command') cmd;; 'Password') password;;
'Command to clipboard') cmd_clip;; 'Alternate password') other_password;;
'Username') username;; 'Show calender') notify-send 'Calender' "\n\n$(cal)";;
'Password') password;; #This should check for an error code and confirm that download has started
'Alternate password') other_password;; '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";;
'Show calender') notify-send 'Calender' "\n\n$(cal)";; esac
#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";; do_search() {
'Go page') num=$(go_page); pages pager $num;; type=$(printf "Manual
esac DDG
Godocs
Mojeek
Package
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";;
Github) github;;
Godocs) godoc;;
DDG) ddg;;
Package) package;;
esac
}

package() {
type=$(printf "search\ninfo" | dmenu -p 'package')
if [ -z "$type" ]; then
exit
elif [ "$type" = "info" ]; then
s=$(dmenu_path | dmenu -i -p 'package info')
st -e sh -lc "apt-cache show $s"
else
s=$(dmenu -i -p 'package search')
st -e sh -lc "apt search \"$s\""
fi
}

editor() {
#handle spacing in filenames bug
file=$(mru list | dmenu -i -l 10 -p 'edit what?')
if [ -z "$file" ]; then exit; fi
first=$(printf "$file" | head -n1 -)
d=$(dirname "$first")
files=$(printf "$file" | tr '\n' ' ')
printf "files: $files"
st -t 'Editor' -e vim "+cd $d" $files
}

opener() {
mru list | dmenu -i -l 20 -p 'open' | while read f; do xdg-open $f; done
} }


screenshot() { screenshot() {
@@ -217,6 +243,7 @@ infowindow() {


cmd() { cmd() {
c="$(printf '' | dmenu -i -p 'cmd')" c="$(printf '' | dmenu -i -p 'cmd')"

output=$( $c ) output=$( $c )
notify-send -u low 'command output' "$output" notify-send -u low 'command output' "$output"
} }
@@ -274,15 +301,13 @@ edit_password() {
case $1 in case $1 in
launch) launch;; launch) launch;;
action) action;; action) action;;
cmd) action;; cmd) cmd;;
cmd_clip) cmd_clip;; cmd_clip) cmd_clip;;
ddg) ddg;;
github) github;;
godoc) godoc;;
goinfo) goinfo;;
username) username;; username) username;;
password) password;; password) password;;
other_password) other_password;; other_password) other_password;;
edit_password) edit_password;; edit_password) edit_password;;
search) do_search;;
open) opener;;
*) printf "Invalid argument";; *) printf "Invalid argument";;
esac esac

+ 3
- 0
text-opener Voir le fichier

@@ -0,0 +1,3 @@
#!/bin/sh

st -t 'Editor' -e vim $*

||||||
x
 
000:0
Chargement…
Annuler
Enregistrer