aboutsummaryrefslogtreecommitdiff
path: root/base/.local/bin/plumb
blob: a242b91c43202d7fa9f41aecd7ff052191e62c8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash

#############
# - plumb - #
#############
#
# Small script to emmulate plan9 plumb. Reimplementation of Luke Smith's script.
# Dependencies:
#
# * xclip: get text from clipboard (normally selected with mouse)
# * xprop: get working directory from current window
# * readlink: to transform symlink to real path
# * xdg-open
# * qrencode
#
# I recommend you to have properly configured xdg-mime for different extensions.
# For example:
#
# xdg-mime default sxiv.desktop image/jpeg image/png
#
# You can query what kind of mime type is one file using:
#
# xdg-mime query filetype FILENAME
#

TERMINAL=st
FILE_MANAGER=ranger
DMENU_FONT=terminus

data=$(xclip -o)
[ -z "$data" ] && exit

# Lets search for the current focused window info
win_id=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | awk '{print $5}')
win_pid=$(xprop -id $win_id | grep "_NET_WM_PID(CARDINAL)" | awk '{print $3}')
path="$(readlink /proc/$win_pid/cwd)"
cd $path

[ -f "$data" ] && xdg-open  "$data" && exit
[ -d "$data" ] && "$TERMINAL" "$FILE_MANAGER" "$path/$data" && exit

open() { xdg-open $data ; }
web_search() { xdg-open "https://duckduckgo.com/?q=$data" ; }
gen_qr() { echo $data | xargs qrencode -o /tmp/qr.png | xdg-open /tmp/qr.png ; }
manual() { "$TERMINAL" "/usr/bin/man" $data ; }

func="$(declare -F | cut -d ' ' -f 3 | dmenu -fn $DMENU_FONT -p "Plump $data to?" -i -l 15)"

"$func"