浏览代码

Add mru code and reformat readme

master
= 3 年前
父节点
当前提交
ada35e3d44
共有 4 个文件被更改,包括 119 次插入38 次删除
  1. +59
    -22
      README.md
  2. +39
    -0
      mru
  3. +9
    -12
      pages
  4. +12
    -4
      prompt

+ 59
- 22
README.md 查看文件

@@ -3,49 +3,85 @@
This is a collection of scripts I use to make managing files and processes easier.
Use it to automagically select and run terminal applications, send signals to daemons, execute arbitrary commands, search the web, grab passwords from a password manager, and more.

## Installing dependencies
### Installing dependencies
`sudo apt install pass enscript dunst xclip scrot mpc mpd ghostscript zathura
suckless-tools youtube-dl`

All of them are optional except suckless-tools. Many of the features aren't interdependent and are made up of 1 or 2 functions.
All of them are optional except suckless-tools. Many of the features aren't
interdependent and are made up of 1 or 2 functions.

- [ dmenu ](http://tools.suckless.org/dmenu/) is for the prompts. It can be
changed to rofi or some other solution
- scrot and xclip for screenshots
- all scripts assume your prefered terminal is [ st ](http://st.suckless.org)
- mpc is for media controls
- zathura, ghostscript, and enscript are an aesthetic option for viewing man
pages and command outputs as document files rather than terminal output

## prompt
It's the central script that gives the rest of the features interactivity. Read the source code for more details.
The central script that gives the rest of the features interactivity. Read
the source code for more details.
### Usage
prompt [ launch | action | cmd | cmd_clip | github | godoc | ddg | manual | username | password | other_password | edit_password | open | edit ]
prompt [ COMMAND ]

#### COMMANDS
* launch
* action
* cmd
* cmd_clip
* github
* godoc
* ddg
* manual
* username
* password
* other_password
* edit_password
* 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.
`prompt launch` and `prompt action` are the only commands you really need to
know because they will prompt for all the rest. The other command line subcommands are for
convenience and may be removed in the future.
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
* You may want to bind Mod4+a to `launch action` and Mod4+g to `prompt launch`

##mru
## mru
Used for indexing and ranking frequently accessed files to ~/.cache/mru
mru [COMMAND] [CACHE]

#### COMMMAND
- init
- update
- output
- list

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

## pages
pages is a command for viewing /tmp/pages-{number} files with less or zathura.
The files are the result of prompt commands like `prompt action` -> Go page or
can be created from your own tools. I use it for viewing documentation.
### Usage
pages [ open ]

### Usage
pages [ pager | pdf | browser | send ] [ NAME ]

- [ dmenu ](http://tools.suckless.org/dmenu/) for the prompts. It can be changed to rofi or some other solution
- scrot and xclip for screenshots
- all scripts assume your prefered terminal is [ st ](http://st.suckless.org)
- mpc is for media controls
- commands that display information from man pages, godoc, logs, etc
do it using `enscript -p - | ps2pdf - | zathura -`. I'm considering
more minimal combinations like enscript and surf or st and less but
they create their own set of problems. This solution makes future
changes easy without becoming too complicated
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.

Use it to automagically select and run terminal applications, send signals to daemons, execute arbitrary commands, search the web, grab passwords from the password manager, and more.
#### Notes
* Page names don't have to be numbers, here is an example vim Ex mode command I
use to convert a markdown file to html and open it in a browser: `:!markdown
% | pages send 1.html | pages browser 1.html` This could then be given it's
own keybinding.
Use it to automagically select and run terminal applications, send signals to
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
@@ -61,4 +97,5 @@ Use it to automagically select and run terminal applications, send signals to da
- Make password prompts green
- Figure out range selecting for parsing passwords
- Figure out using dmenu instead of gnome key prompt
- Give launched st windows better naming
- Consider entr, inotifywait, auditctl, or find -atime for MRU
- setup xdg-open. Need it for opener and editors

+ 39
- 0
mru 查看文件

@@ -1,4 +1,43 @@
#!/bin/sh

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

init() {
mkdir -p $XDG_CACHE_HOME/mru
}

get_cache_path() {
if [ -z "$1" ]; then printf "invalid arg to cache_path\n"; exit; fi
}

update() {
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"; 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
}

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

list() {
output "$1" | cut -f3
}

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

+ 9
- 12
pages 查看文件

@@ -1,17 +1,14 @@
#!/bin/sh

pager() {
# st -e tail -F -n +1 "/tmp/pages-$1"
st -e less "/tmp/pages-$1"
}
if [ -z "$1" -o -z "$2" ]; then
printf "Invalid number of arguments\n"
exit
fi

pdf() {
st -e zathura "/tmp/pages-$1"
}

case $1 in
pager) pager "$2";;
pdf) pdf "$2";;
case "$1" in
pager) st -t "Page $1" -e less "/tmp/pages-$2";;
pager) zathura "/tmp/pages-$2";;
browser) brave-browser "/tmp/pages-$2";;
send) cat - > /tmp/pages-$2;;
esac

+ 12
- 4
prompt 查看文件

@@ -6,6 +6,7 @@ browser_new_cmd="brave-browser --new-window"
launch() {
app=$(printf "Notes
Files
Edit
Editor
Terminal
Multiplexer
@@ -20,23 +21,28 @@ launch() {
Define
Package search
Package info
Play clipboard
Play downloads
Processes" | tr -d '\t' |
dmenu -i -p "Launcher")

case $app in
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;;
Terminal) st -t "Terminal";;
Page) pages pager "$(printf "1\n2\n3\n" | dmenu -p 'page')";;
Manual) st -e man "$(printf "" | dmenu -p 'man')";;
Multiplexer) st -t "Multiplexer" -e tmux attach || st -t "Multiplexer" -e tmux;;
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;;
Chat) element-desktop;;
Music) st -t "Music" -e ncmpcpp;;
Browser) $browser_cmd;;
'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')";;
'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";;
@@ -45,7 +51,8 @@ launch() {
}

editor() {
type=$(printf "Recent\nProjects\nSource\nConfigs\nMacros" | dmenu -i -p 'edit what?')
file=$(mru list | dmenu -i -l 10 -p 'edit what?')
st -t 'Editor' -e vim "$file"
}

#Opening all mru files, not just for editing
@@ -68,6 +75,7 @@ action() {
Enable VPN
VPN Status
Rebind Keys
Show calender
Disable Bar
Password
Username
@@ -91,6 +99,7 @@ case $action in
'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;;
@@ -271,7 +280,6 @@ case $1 in
github) github;;
godoc) godoc;;
goinfo) goinfo;;
manual) manual;;
username) username;;
password) password;;
other_password) other_password;;


正在加载...
取消
保存