Skip to content

Instantly share code, notes, and snippets.

@rkmax
Created October 15, 2024 14:51
Show Gist options
  • Save rkmax/e120728ef205ca1ff41c95e81d68a1f3 to your computer and use it in GitHub Desktop.
Save rkmax/e120728ef205ca1ff41c95e81d68a1f3 to your computer and use it in GitHub Desktop.
#!/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