From 05a37736b6e387e79419d56ec09538ab27af2971 Mon Sep 17 00:00:00 2001 From: Chris Guest Date: Mon, 17 Oct 2022 11:16:40 +0100 Subject: [PATCH 1/2] disable copilot - adding a start and backup option. --- 43_awk/README.md | 14 +++++ 67_disable_copilot_for_workspace/.gitignore | 1 + 67_disable_copilot_for_workspace/README.md | 1 + .../disable-copilot.sh | 59 ++++++++++++++++--- 4 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 67_disable_copilot_for_workspace/.gitignore diff --git a/43_awk/README.md b/43_awk/README.md index 949eba3..e67930f 100644 --- a/43_awk/README.md +++ b/43_awk/README.md @@ -15,6 +15,12 @@ cat example1.txt | awk '{print $1,$2,$3}' cat example1.txt | awk '{if(!$3) {print $1,$2} else {print $1,$3;print $1,$2}}' ``` +## CSV + +```sh +awk -F "," '{print $1}' +``` + ## Prepending text ```sh @@ -22,6 +28,14 @@ cat example1.txt | awk '{if(!$3) {print $1,$2} else {print $1,$3;print $1,$2}}' cat example1.txt | awk '{print "stdout:" $0;}' ``` +## Trimming + +```sh +# white space + +# replace a character +``` + ## Processing LDD output ```sh diff --git a/67_disable_copilot_for_workspace/.gitignore b/67_disable_copilot_for_workspace/.gitignore new file mode 100644 index 0000000..c0baf1e --- /dev/null +++ b/67_disable_copilot_for_workspace/.gitignore @@ -0,0 +1 @@ +backups diff --git a/67_disable_copilot_for_workspace/README.md b/67_disable_copilot_for_workspace/README.md index 56b8fc9..dc51470 100644 --- a/67_disable_copilot_for_workspace/README.md +++ b/67_disable_copilot_for_workspace/README.md @@ -6,6 +6,7 @@ A script to disable extensions by workspace. TODO: +* Can I get to work on linux as well? * Test if workspace folder exists. * Seems to be a problem with vscode caching. * Get it to load a set of extensions to install and disable from a config file diff --git a/67_disable_copilot_for_workspace/disable-copilot.sh b/67_disable_copilot_for_workspace/disable-copilot.sh index 0e3ae29..b2cb702 100755 --- a/67_disable_copilot_for_workspace/disable-copilot.sh +++ b/67_disable_copilot_for_workspace/disable-copilot.sh @@ -38,10 +38,28 @@ OPTIONS: --disable disable extension --status current extension status --start start workspace + --backup backup workspace db Examples: $SCRIPT_NAME --help + list all the workspaces + $SCRIPT_NAME --list + + list a set of workspaces + $SCRIPT_NAME --list --workspace=\/shell_examples + + status of copilot for workspace + $SCRIPT_NAME --status --workspace=shell_examples + + disable copilot for workspace + $SCRIPT_NAME --disable --workspace=shell_examples + + enable copilot for workspace + $SCRIPT_NAME --enable --workspace=shell_examples + + start vscode in folder + $SCRIPT_NAME --start --workspace=shell_examples EOF } @@ -74,6 +92,9 @@ case $i in --start) START=true ;; + --backup) + BACKUP=true + ;; -w=*|--workspace=*) WORKSPACE="${i#*=}" shift # past argument=value @@ -94,6 +115,7 @@ _supported=false case "${OSTYPE}" in MAC) _supported=true + WORKSPACE_BASE_PATH="$HOME/Library/Application Support/Code/User/workspaceStorage" ;; LINUX) ;; @@ -113,15 +135,14 @@ fi check_prerequisites sqlite3 jq if [[ $LIST == true ]]; then - PROJECT= - find $HOME/Library/Application\ Support/Code/User/workspaceStorage -iname "workspace.json" -exec jq --arg filename {} -c '. | {"folder": .folder, "filename": $filename}' {} \; | jq -s '.' | jq --arg project "${PROJECT}" '.[] | select(.folder != null) | select(.folder | test(".*\( $project )"))' | jq -s . + PROJECT="${WORKSPACE}$" + find "${WORKSPACE_BASE_PATH}" -iname "workspace.json" -exec jq --arg filename {} -c '. | {"folder": .folder, "filename": $filename}' {} \; | jq -s '.' | jq --arg project "${PROJECT}" '.[] | select(.folder != null) | select(.folder | test(".*\( $project )"))' | jq -s . else - if [ $ENABLE == false ] && [ $DISABLE == false ] && [ $STATUS == false ] && [ $START == false ]; then + if [ $ENABLE == false ] && [ $DISABLE == false ] && [ $STATUS == false ] && [ $START == false ] && [ $BACKUP == false ]; then help exit 0 else - if [[ -z ${WORKSPACE} ]]; then >&2 echo "--workspace is not set" exit 1 @@ -135,7 +156,7 @@ else echo "Searching..." OUTFILE=$(mktemp) echo "PROJECT='${PROJECT}'" - DBPATH=$(dirname "$(find $HOME/Library/Application\ Support/Code/User/workspaceStorage -iname "workspace.json" -exec jq --arg filename {} -c '. | {"folder": .folder, "filename": $filename}' {} \; | jq -s '.' | jq --arg project "${PROJECT}" '.[] | select(.folder != null) | select(.folder | test(".*\( $project )"))' | jq -s -r '.[].filename' | tail -n 1)") + DBPATH=$(dirname "$(find "${WORKSPACE_BASE_PATH}" -iname "workspace.json" -exec jq --arg filename {} -c '. | {"folder": .folder, "filename": $filename}' {} \; | jq -s '.' | jq --arg project "${PROJECT}" '.[] | select(.folder != null) | select(.folder | test(".*\( $project )"))' | jq -s -r '.[].filename' | head -n 1)") DBFILE="${DBPATH}/state.vscdb" echo "DBPATH='${DBPATH}'" @@ -155,7 +176,7 @@ else echo "Searching..." OUTFILE=$(mktemp) echo "PROJECT='${PROJECT}'" - DBPATH=$(dirname "$(find $HOME/Library/Application\ Support/Code/User/workspaceStorage -iname "workspace.json" -exec jq --arg filename {} -c '. | {"folder": .folder, "filename": $filename}' {} \; | jq -s '.' | jq --arg project "${PROJECT}" '.[] | select(.folder != null) | select(.folder | test(".*\( $project )"))' | jq -s -r '.[].filename' | tail -n 1)") + DBPATH=$(dirname "$(find "${WORKSPACE_BASE_PATH}" -iname "workspace.json" -exec jq --arg filename {} -c '. | {"folder": .folder, "filename": $filename}' {} \; | jq -s '.' | jq --arg project "${PROJECT}" '.[] | select(.folder != null) | select(.folder | test(".*\( $project )"))' | jq -s -r '.[].filename' | head -n 1)") DBFILE="${DBPATH}/state.vscdb" echo "DBPATH='${DBPATH}'" @@ -175,7 +196,7 @@ else if [[ $STATUS == true ]]; then echo "Searching..." echo "PROJECT='${PROJECT}'" - DBPATH=$(dirname "$(find $HOME/Library/Application\ Support/Code/User/workspaceStorage -iname "workspace.json" -exec jq --arg filename {} -c '. | {"folder": .folder, "filename": $filename}' {} \; | jq -s '.' | jq --arg project "${PROJECT}" '.[] | select(.folder != null) | select(.folder | test(".*\( $project )"))' | jq -s -r '.[].filename' | tail -n 1)") + DBPATH=$(dirname "$(find "${WORKSPACE_BASE_PATH}" -iname "workspace.json" -exec jq --arg filename {} -c '. | {"folder": .folder, "filename": $filename}' {} \; | jq -s '.' | jq --arg project "${PROJECT}" '.[] | select(.folder != null) | select(.folder | test(".*\( $project )"))' | jq -s -r '.[].filename' | head -n 1)") DBFILE="${DBPATH}/state.vscdb" echo "DBPATH='${DBPATH}'" @@ -188,7 +209,7 @@ else if [[ $START == true ]]; then echo "Searching..." echo "PROJECT='${PROJECT}'" - WORKSPACEPATH=$(find $HOME/Library/Application\ Support/Code/User/workspaceStorage -iname "workspace.json" -exec jq --arg filename {} -c '. | {"folder": .folder, "filename": $filename}' {} \; | jq -s '.' | jq --arg project "${PROJECT}" '.[] | select(.folder != null) | select(.folder | test(".*\( $project )"))' | jq -s -r '.[].folder' | tail -n 1) + WORKSPACEPATH=$(find "${WORKSPACE_BASE_PATH}" -iname "workspace.json" -exec jq --arg filename {} -c '. | {"folder": .folder, "filename": $filename}' {} \; | jq -s '.' | jq --arg project "${PROJECT}" '.[] | select(.folder != null) | select(.folder | test(".*\( $project )"))' | jq -s -r '.[].folder' | head -n 1) echo "WORKSPACEPATH='${WORKSPACEPATH}'" REALWORKSPACEPATH="${WORKSPACEPATH//file:\/\//}" @@ -197,5 +218,27 @@ else code "${REALWORKSPACEPATH}" fi + if [[ $BACKUP == true ]]; then + # TODO: Compare backup db to one with extension disabled. + echo "Searching..." + echo "PROJECT='${PROJECT}'" + # use @tsv but then awk has to process tabs + WORKSPACEPATHS=$(find "${WORKSPACE_BASE_PATH}" -iname "workspace.json" -exec jq --arg filename {} -c '. | {"folder": .folder, "filename": $filename}' {} \; | jq -s -c '.' | jq -c --arg project "${PROJECT}" '.[] | select(.folder != null) | select(.folder | test(".*\( $project )"))' | jq -s -r -c '.[0] | [.filename, .folder] | @csv') + echo "WORKSPACEPATHS=${WORKSPACEPATHS}" + WORKSPACEJSON=$(echo ${WORKSPACEPATHS} | awk -F "," '{print $1}') + WORKSPACEFOLDER=$(echo ${WORKSPACEPATHS} | awk -F "," '{print $2}') + + DBFILE=$(dirname "$WORKSPACEJSON")/state.vscdb + WORKSPACENAME=$(basename $WORKSPACEFOLDER) + + echo "DBFILE=${DBFILE}" + echo "WORKSPACEFOLDER=${WORKSPACEFOLDER}" + echo "WORKSPACENAME=${WORKSPACENAME}" + + #echo "${DBFILE} ./backups/db" + #mkdir -p ./backups/db + #cp "${DBFILE}" ./backups/db + fi + fi fi From d5c3aea2460e0ff7fee0e479f9095ac466a5dd9c Mon Sep 17 00:00:00 2001 From: Chris Guest Date: Mon, 17 Oct 2022 22:27:41 +0100 Subject: [PATCH 2/2] Add a todo --- 67_disable_copilot_for_workspace/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/67_disable_copilot_for_workspace/README.md b/67_disable_copilot_for_workspace/README.md index dc51470..554c43e 100644 --- a/67_disable_copilot_for_workspace/README.md +++ b/67_disable_copilot_for_workspace/README.md @@ -11,6 +11,7 @@ TODO: * Seems to be a problem with vscode caching. * Get it to load a set of extensions to install and disable from a config file * Write it in golang +* Get a list of all installed extensions and run against a whitelist. ## Examples