瀏覽代碼

Finish mru insert and init

master
= 3 年之前
父節點
當前提交
98da93c6b7
共有 5 個文件被更改,包括 164 次插入69 次删除
  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 查看文件

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

Generaly, prompt has two types of commands, launch commands and action
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.
most functionality is accessible from launch and action only

### 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`
* Some prompts like `search package` will infer with their default operation
when the string entered is an invalid selection

## 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]

#### COMMMAND
@@ -59,8 +57,12 @@ Used for indexing and ranking frequently accessed files to ~/.cache/mru
- update
- output
- 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
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
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
* 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.

#### 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
- setup pass
- variables to the script to make assumed paths easier to change
@@ -97,5 +103,6 @@ password manager, and more.
- Make password prompts green
- Figure out range selecting for parsing passwords
- Figure out using dmenu instead of gnome key prompt
- Consider entr, inotifywait, auditctl, or find -atime for MRU
- setup xdg-open. Need it for opener and editors
- Consider entr in dwm-start for watching files
- make dmenu load time more like fzf?
- change xdg text/plain opener to use vim and st if not in terminal

+ 52
- 7
mru 查看文件

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

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

init() {
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() {
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() {
clean
file=$XDG_CACHE_HOME/mru/"$1"
if [ -z "$1" ]; then file="$file""home"; fi
path=$(printf $cache_info | grep "^$1" - | cut -d: -f2)
@@ -19,14 +36,18 @@ update() {
if [ -z "$path" -o ! -e "$path" ]; then
printf "path:$path from cache:$file does not exist\n"; 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
#init a temporary file. The traverse the original, if a file exists in a
# but not in b, delete it from a, if it exists in a and b delete it from b.
# 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() {
if [ -z "$2" ]; then
cat $XDG_CACHE_HOME/mru/home; else cat "$XDG_CACHE_HOME/mru/$2";
if [ -z "$1" ]; then
cat $XDG_CACHE_HOME/mru/home; else cat "$XDG_CACHE_HOME/mru/$1";
fi
}

@@ -34,10 +55,34 @@ list() {
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
init) init "$2";;
update) update $2;;
output) output "$2";;
list) list "$2";;
insert) insert "$2";;
insert) insert "$2" "$3";;
clean) clean;;
esac

+ 15
- 0
pinentry 查看文件

@@ -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 查看文件

@@ -8,6 +8,7 @@ launch() {
Files
Edit
Editor
Open
Terminal
Multiplexer
LBRY
@@ -15,11 +16,10 @@ launch() {
Music
Browser
Hidden browser
Manual
Email
Page
Define
Package search
Go page
Package info
Play clipboard
Play downloads
@@ -30,12 +30,13 @@ launch() {
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;;
Editor) st -t "Editor" -e vim "+CtrlPMRUFiles";;
Open) opener;;
Terminal) st -t "Terminal";;
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;;
LBRY) lbry;;
'Go page') num=$(go_page); pages pager $num;;
Chat) element-desktop;;
Music) st -t "Music" -e ncmpcpp;;
Browser) $browser_cmd;;
@@ -43,33 +44,17 @@ launch() {
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')";;
'Define') word=$(printf '' | dmenu -p 'word'); 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";;
Define) word=$(printf '' | dmenu -p 'word'); if [ -z "$word" ]; then exit; fi; st -e sh -lc "dict \"$word\" | less";;
Processes) st -t "Processes" -e htop;;
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=$(printf "Toggle Music
Pause Music
Play Music
Go page
Command
Command to clipboard
Search github
Search ddg
Search godoc
Select VPN
Disable VPN
Enable VPN
@@ -84,26 +69,67 @@ action() {
Enable Bar" | tr -d '\t' |
dmenu -i -p "Actions")

case $action in
'Play Music') mpc play ;;
'Pause Music') mpc pause ;;
'Toggle Music') mpc toggle ;;
'Rebind Keys') setup-xbindkeys;;
'Disable Bar') tmux set -g status off;;
'Enable Bar') tmux set -g status on;;
'Search github') github;;
'Search godoc') godoc;;
'Search ddg') ddg;;
'Command') cmd;;
'Command to clipboard') cmd_clip;;
'Username') username;;
'Password') password;;
'Alternate password') other_password;;
'Show calender') notify-send 'Calender' "\n\n$(cal)";;
#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";;
'Go page') num=$(go_page); pages pager $num;;
esac
case $action in
'Play Music') mpc play ;;
'Pause Music') mpc pause ;;
'Toggle Music') mpc toggle ;;
'Rebind Keys') setup-xbindkeys;;
'Disable Bar') tmux set -g status off;;
'Enable Bar') tmux set -g status on;;
'Command') cmd;;
'Command to clipboard') cmd_clip;;
'Username') username;;
'Password') password;;
'Alternate password') other_password;;
'Show calender') notify-send 'Calender' "\n\n$(cal)";;
#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";;
esac
}

do_search() {
type=$(printf "Manual
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() {
@@ -217,6 +243,7 @@ infowindow() {

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

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

+ 3
- 0
text-opener 查看文件

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

st -t 'Editor' -e vim $*

Loading…
取消
儲存