Add rofi scripts & replace scratch terminal w/ emacs frame

This commit is contained in:
Henrik Lissner 2019-11-26 17:04:14 -05:00
parent 3a8a306ba9
commit eba864d724
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
11 changed files with 161 additions and 42 deletions

56
bin/rofi/bookmarks Executable file
View file

@ -0,0 +1,56 @@
#!/usr/bin/env bash
# Interactively select (in skim) bookmarks to open from Firefox or
# Chrome/Chromium (depends on $BROWSER). Should work on Linux and MacOS.
#
# requires: sqlite3, jq (if you use chrome/chromium)
sep='{{::}}'
_do_rofi() {
for url in $(awk -F "${1:-$sep}" '{printf "%s, %s\n", $1, $2}' | rofi -dmenu -p 'bookmarks > ' -multi-select | sed 's#.*\(https*://\)#\1#'); do
if command -v "$BROWSER" >/dev/null; then
$BROWSER "$url" &
elif command -v open >/dev/null; then
open "$url" &
else
xdg-open "$url" &
fi
done
}
case ${BROWSER:-firefox} in
firefox)
for dir in ~/.mozilla/firefox/*.default \
$XDG_CONFIG_HOME/firefox/.mozilla/firefox/*.default \
$XDG_DATA_HOME/mozilla/firefox/*.default \
~/Library/Application\ Support/Firefox/Profiles/*.default; do
if [[ -d "$dir" ]]; then
# The db can be locked from time to time. This is inefficient, but
# places.sqlite is usually under 30mb so this should be instant, and
# /tmp is cleared at boot so...
cp "$dir/places.sqlite" "/tmp/places.sqlite"
sqlite3 -separator $sep "/tmp/places.sqlite" \
"SELECT DISTINCT mb.title, mp.url FROM moz_bookmarks mb \
INNER JOIN moz_places mp ON mp.id = mb.fk \
WHERE mb.type = 1 AND mb.title IS NOT NULL \
ORDER BY mp.frecency DESC" | _do_rofi
break
fi
done
;;
qutebrowser)
sed -e 's/ /{{::}}/' urls | awk -F'{{::}}' '{printf "%s{{::}}%s\n", $2, $1}' | _do_rofi
;;
*)
for dir in ~/.config/google-chrome/Default ~/.config/chromium/Default ~/Library/Application\ Support/Google/Chrome/Default; do
# requires jq
if [[ -f "$dir/Bookmarks" ]]; then
jq -r '.. | [.name, .url]? | @tsv' "$dir/Bookmarks" | \
sed '/^[ \t]*$/d;/\t$/d;/\tchrome:\/\//d' | \
_do_rofi "\t"
break
fi
done
;;
esac

2
bin/rofi/calc Executable file
View file

@ -0,0 +1,2 @@
#!/usr/bin/env bash
rofi -show calc -modi "calc:qalc +u8"

6
bin/rofi/file Executable file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env sh
DIR="$(fd -L --type d . $HOME | rofi -dmenu)"
if [ -d "$DIR" ]; then
cd "$DIR"
xst
fi

59
bin/rofi/history Executable file
View file

@ -0,0 +1,59 @@
#!/usr/bin/env bash
# Interactively select (in skim) an url from Firefox/Chrome/Chromium history to
# open in your browser (depends on $BROWSER). Should work on Linux and MacOS.
#
# requires: sqlite3
sep='{{::}}'
_do_rofi() {
for url in $(awk -F "${1:-$sep}" '{printf "%s, %s\n", $1, $2}' | rofi -dmenu -p='history > ' -multi-select | sed 's#.*\(https*://\)#\1#'); do
if command -v "$BROWSER" >/dev/null; then
$BROWSER "$url" &
elif command -v open >/dev/null; then
open "$url" &
else
xdg-open "$url" &
fi
done
}
case ${BROWSER:-firefox} in
qutebrowser)
sqlite3 -separator $sep "$XDG_DATA_HOME/qutebrowser/history.sqlite" \
"SELECT title, url FROM History \
WHERE title != '' \
GROUP BY url \
ORDER BY atime DESC" | _do_rofi
;;
firefox)
for dir in ~/.mozilla/firefox/*.default \
$XDG_CONFIG_HOME/firefox/.mozilla/firefox/*.default \
$XDG_DATA_HOME/mozilla/firefox/*.default \
~/Library/Application\ Support/Firefox/Profiles/*.default; do
if [[ -d "$dir" ]]; then
# The db can be locked from time to time. This is inefficient, but
# places.sqlite is usually under 30mb so this should be instant, and
# /tmp is cleared at boot so...
cp "$dir/places.sqlite" "/tmp/places.sqlite"
sqlite3 -separator $sep "/tmp/places.sqlite" \
"SELECT DISTINCT title, url FROM moz_places \
WHERE title IS NOT NULL \
ORDER BY last_visit_date DESC" | _do_rofi
break
fi
done
;;
*)
for dir in ~/.config/google-chrome/Default ~/.config/chromium/Default ~/Library/Application\ Support/Google/Chrome/Default; do
if [[ -f "$dir/History" ]]; then
cp -f "$dir/History" "/tmp/_h"
sqlite3 -separator $sep "/tmp/_h" \
"SELECT substr(title, 1, $((COLUMNS / 3))), url \
FROM urls ORDER BY last_visit_time DESC" | _do_rofi
break
fi
done
;;
esac

2
bin/rofi/ssh Executable file
View file

@ -0,0 +1,2 @@
#!/usr/bin/env sh
rofi -show ssh -multi-select

View file

@ -15,12 +15,12 @@ bspc config remove_unplugged_monitors true
bspc rule -r '*'
bspc rule -a 'Emacs:org*' state=floating
bspc rule -a 'Emacs:scratch' state=floating
bspc rule -a mpv state=floating center=on
bspc rule -a Pinentry state=floating center=on
bspc rule -a Emacs split_ratio=0.32 state=fullscreen
bspc rule -a Firefox split_ratio=0.32
bspc rule -a feh state=fullscreen
bspc rule -a st-scratch state=floating sticky=on center=on
#

View file

@ -1,4 +0,0 @@
configuration {
m: "-1";
theme: "~/.config/rofi/theme";
}

View file

@ -24,10 +24,10 @@ super + Return
xst
super + grave
st-scratch
emacsclient -a "" -e "(open-scratch-frame)"
super + space
rofi -monitor -4 -show run
rofi -monitor -4 -show drun -show-icons
super + backslash
rofi-pass

View file

@ -27,12 +27,13 @@
environment = {
systemPackages = with pkgs; [
# Just the bear necessities~
libqalculate
coreutils
git
wget
vim
killall
unzip
bc
vim
wget
# Support for extra filesystems
sshfs
exfat

View file

@ -1,10 +1,15 @@
{ config, lib, pkgs, ... }:
{
imports = [ ./. ];
imports = [
./.
./rofi.nix
];
environment = {
systemPackages = with pkgs; [
xst # st + nice-to-have extensions
lightdm
bspwm
dunst
@ -14,39 +19,13 @@
pulseSupport = true;
nlSupport = true;
})
killall
rofi
(writeScriptBin "rofi" ''
#!${stdenv.shell}
exec ${rofi}/bin/rofi -config "$XDG_CONFIG_HOME/rofi/config" $@
'')
xst # st + nice-to-have extensions
# A quick 'n dirty script for opening a scratch terminal.
(writeScriptBin "st-scratch" ''
#!${stdenv.shell}
SCRID=st-scratch
focused=$(xdotool getactivewindow)
scratch=$(xdotool search --onlyvisible --classname $SCRID)
if [[ -n $scratch ]]; then
if [[ $focused == $scratch ]]; then
xdotool windowkill $scratch
else
xdotool windowactivate $scratch
fi
else
xst -t $SCRID -n $SCRID -c $SCRID \
-f "$(xrdb -query | grep 'st-scratch\.font' | cut -f2)" \
-g 100x26 \
-e $SHELL
fi
'')
];
};
fonts.fonts = [ pkgs.siji ];
programs.zsh.interactiveShellInit = "export TERM=xterm-256color";
services = {
xserver = {
desktopManager.xterm.enable = false;
@ -66,9 +45,7 @@
home-manager.users.hlissner.xdg.configFile = {
"sxhkd".source = <config/sxhkd>;
# link recursively so other modules can link files in their folders, e.g.
# ~/.config/bspwm/rc.d and ~/.config/rofi/theme
# link recursively so other modules can link files in their folders
"bspwm" = { source = <config/bspwm>; recursive = true; };
"rofi" = { source = <config/rofi>; recursive = true; };
};
}

20
modules/desktop/rofi.nix Normal file
View file

@ -0,0 +1,20 @@
{ config, lib, pkgs, ... }:
{
environment = {
systemPackages = with pkgs; [
(writeScriptBin "rofi" ''
#!${stdenv.shell}
exec ${rofi}/bin/rofi -terminal xst -theme "$XDG_CONFIG_HOME/rofi/theme" -m -1 $@
'')
rofi
];
# shellAliases = {};
};
home-manager.users.hlissner.xdg.configFile = {
# link recursively so other modules can link files in its folder
"rofi" = { source = <config/rofi>; recursive = true; };
};
}