From fbea6384b5c2de8dd25028ae43ce50073181ea25 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Sat, 18 Feb 2023 17:52:24 -0500 Subject: [PATCH] Add history and project search to rofi --- fake_home/.config/rofi/config.rasi | 23 ++++++++++--- fake_home/.gitconfig | 2 ++ fake_home/.rofi-history-search.sh | 16 +++++++++ fake_home/.rofi-list-git-repos.sh | 53 ++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 4 deletions(-) create mode 100755 fake_home/.rofi-history-search.sh create mode 100755 fake_home/.rofi-list-git-repos.sh diff --git a/fake_home/.config/rofi/config.rasi b/fake_home/.config/rofi/config.rasi index e110d9c..a69b13d 100644 --- a/fake_home/.config/rofi/config.rasi +++ b/fake_home/.config/rofi/config.rasi @@ -1,6 +1,14 @@ configuration { modes: [ combi, emoji ]; - combi-modes: [ window, drun, emoji, "tabs:/home/sage/.rofi-tabs.sh" ]; + sort: true; + combi-modes: [ + window, + drun, + emoji, + "tabs:/home/sage/.rofi-tabs.sh", + // "history:/home/sage/.rofi-history-search.sh", + "projects:/home/sage/.rofi-list-git-repos.sh" + ]; show-icons: true; drun { display-name: ""; @@ -13,15 +21,22 @@ configuration { } tabs { display-name: ""; + fallback-icon: "firefox-beta"; + } + history { + display-name: ""; + fallback-icon: "firefox-beta"; } } -@theme "/usr/share/rofi/themes/gruvbox-dark-hard.rasi" +//@theme "/usr/share/rofi/themes/gruvbox-dark-hard.rasi" +//@theme "/usr/share/rofi/themes/Arc-Dark.rasi" +@theme "/usr/share/rofi/themes/android_notification.rasi" textbox-prompt-sep { - str: ">"; + // str: ">"; } inputbar { - children: [ "textbox-prompt-sep","entry","case-indicator" ]; + // children: [ "textbox-prompt-sep","entry","case-indicator" ]; } diff --git a/fake_home/.gitconfig b/fake_home/.gitconfig index 751d95e..3510408 100644 --- a/fake_home/.gitconfig +++ b/fake_home/.gitconfig @@ -25,3 +25,5 @@ verbose = true [pull] rebase = false +[protocol "file"] + allow = always diff --git a/fake_home/.rofi-history-search.sh b/fake_home/.rofi-history-search.sh new file mode 100755 index 0000000..2a167f7 --- /dev/null +++ b/fake_home/.rofi-history-search.sh @@ -0,0 +1,16 @@ +FIREFOX_PROFILE="$HOME/.mozilla/firefox/qzw6ae3r.default-beta" +PLACES_FILE="$FIREFOX_PROFILE/places.sqlite" +WORKING_PLACES="$FIREFOX_PROFILE/places2.sqlite" +CACHE_FILE="$HOME/.rofi-history-cache" + +function duplicate_history_file() { + cp $PLACES_FILE $WORKING_PLACES +} + +if [[ "$1" == "" ]] && [[ "1" == "$(( (`date +%s` - `stat -L --format %Y $CACHE_FILE.sqlite`) > (30*60) ))" ]]; then + duplicate_history_file + sqlite3 "$WORKING_PLACES" "SELECT datetime(a.visit_date/1000000,'unixepoch') AS visit_date, b.title, b.url FROM moz_historyvisits AS a JOIN moz_places AS b ON a.place_id=b.id WHERE 1 ORDER BY a.visit_date DESC LIMIT 10000;" > "$CACHE_FILE" + cat "$CACHE_FILE" +else + firefox-beta-bin "$(grep "$1" "$CACHE_FILE" | head -n 1 | sed 's/.*|//g')" +fi diff --git a/fake_home/.rofi-list-git-repos.sh b/fake_home/.rofi-list-git-repos.sh new file mode 100755 index 0000000..39dd1fb --- /dev/null +++ b/fake_home/.rofi-list-git-repos.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +GIT_DIRS=("$HOME/work" "$HOME/projects" "$HOME/git" "$HOME/WebStormProjects" "$HOME/RiderProjects") + +function open_app() { + application="$1" + project="$2" + + + exe=$(grep "Exec" "$HOME/.local/share/applications/jetbrains-$application.desktop" | sed 's/.*"\([^"]*\)".*/\1/') + $exe "$project" &> /dev/null & +} + +function file_exists() { + project="$1" + file="$2" + files=($project/$file) + if [ -e "${files[0]}" ]; then + return 0 + else + return 1 + fi +} + +function open_project() { + project="$1" + + if file_exists "$project" "pom.xml"; then + open_app "idea" "$project" + elif file_exists "$project" "package.json"; then + open_app "webstorm" "$project" + elif file_exists "$project" "cargo.toml" || file_exists "$project" "*.c"; then + open_app "clion" "$project" + elif file_exists "$project" "*.csproj"; then + open_app "rider" "$project" + elif file_exists "$project" "*.py"; then + open_app "pycharm" "$project" + elif file_exists "$project" "*.go"; then + open_app "goland" "$project" + else + open_app "idea" "$project" + fi +} + +if [[ "$1" == "" ]]; then + for dir in $(echo ${GIT_DIRS[*]}); do + if [ -e "$dir" ]; then + find $dir -maxdepth 1 -mindepth 1 -type d + fi + done +else + open_project "$1" +fi