Created
October 15, 2024 14:51
-
-
Save rkmax/e120728ef205ca1ff41c95e81d68a1f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# rofi-vscode.sh - A script to open recent files, folders and workspaces in VS Code. | |
# requires: rofi, jq, sqlite3 | |
# | |
# Usage: | |
# rofi -modi "VSCode:rofi-vscode.sh" -show VSCode | |
# | |
vscdb_path="$HOME/.config/Code/User/globalStorage/state.vscdb" | |
get_recent_entries() { | |
sqlite3 "$vscdb_path" "SELECT value FROM ItemTable WHERE key='history.recentlyOpenedPathsList';" | \ | |
jq -r \ | |
'.entries[] | | |
if .folderUri then "folder " + (.folderUri | sub("^file://"; "")) | |
elif .fileUri then "file " + (.fileUri | sub("^file://"; "")) | |
elif .workspace.configPath then "workspace " + (.workspace.configPath | sub("^file://"; "")) | |
else empty end' | |
} | |
get_recent_entries_fmt() { | |
get_recent_entries | while read -r entry; do | |
case $entry in | |
folder*) | |
echo -en "${entry#folder }\0icon\x1ffolder\n" | |
;; | |
file*) | |
echo -en "${entry#file }\0icon\x1ffile\n" | |
;; | |
workspace*) | |
echo -en "${entry#workspace }\0icon\x1ffolder\n" | |
;; | |
esac | |
done | |
} | |
if [[ $ROFI_RETV = 0 ]]; then | |
get_recent_entries_fmt | |
elif [[ $ROFI_RETV = 1 ]]; then | |
coproc code "${@#* }" > /dev/null 2>&1 | |
elif [[ $ROFI_RETV = 2 ]]; then | |
coproc code -a "${@#* }" > /dev/null 2>&1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment