0
0
Просмотр исходного кода

feat(surfingkeys): add SurfingKeys config

Joe 1 год назад
Родитель
Сommit
d176378d2d

+ 1 - 0
.config/.gitignore

@@ -10,6 +10,7 @@
 !lazygit/
 !lazygit/
 !prettier/
 !prettier/
 !skhd/
 !skhd/
+!surfingkeys/
 !tmux/
 !tmux/
 !yabai/
 !yabai/
 !zsh/
 !zsh/

+ 15 - 0
.config/surfingkeys/.gitignore

@@ -0,0 +1,15 @@
+# ignore everything...
+/*
+!.gitignore
+# ...except for these:
+!README.md
+!package.json
+!tsconfig.json
+!index.ts
+!compile.sh
+
+!src/
+!src/**/*/
+!src/**/*.ts
+!src/**/*.js
+!src/**/*.css

+ 16 - 0
.config/surfingkeys/README.md

@@ -0,0 +1,16 @@
+# Surfingkeys Config
+
+Configuration for [Surfingkeys](https://github.com/brookhong/Surfingkeys),
+written in [TypeScript](https://www.typescriptlang.org/).
+
+<details>
+    <summary>Many thanks to the following for their inspiration:</summary>
+- [b0o](http://github.com/b0o/surfingkeys-conf)
+- [decoyjoe](http://gist.github.com/decoyjoe/b708a3d28508c71f2398fefd3d845359)
+- [megalithic](http://github.com/megalithic/dotfiles)
+</details>
+
+This project must be compiled before it can be run. Run `npm run build`, or
+execute [`compile.sh`](./compile.sh) when your browser launches. Then direct the
+[Surfingkeys extension settings](chrome-extension://gfbliohnnapiefjpjlpjnehglfpaknnc/pages/options.html)
+to load settings from the rendered `index.js` file.

+ 26 - 0
.config/surfingkeys/compile.sh

@@ -0,0 +1,26 @@
+#!/bin/zsh
+### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
+# compile.sh
+#
+# This script is made to be called by yabai when Chrome is launched - see
+# `yabairc` for details. This often causes the process to fire twice, so the
+# program requires a lock. Detailed compilation logs are also kept.
+### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
+cd $XDG_CONFIG_HOME/surfingkeys/ &&
+	if mkdir compile.lock 2>/dev/null; then
+		echo "=== === === === === === === === === === ===" | tee -a compile.log
+		echo "                  STARTED                  " | tee -a compile.log
+		echo "=== === === === === === === === === === ===" | tee -a compile.log
+		echo "$(date 2>&1): Compiling" | tee -a compile.log
+		if [ ! -f package-lock.json ]; then
+		    echo "\t$(npm install 2>&1)" | tee -a compile.log
+		fi
+		echo "\t$(npm run build 2>&1)" | tee -a compile.log
+		rm -rf compile.lock
+		echo "=== === === === === === === === === === ===" | tee -a compile.log
+		echo "                  FINISHED                 " | tee -a compile.log
+		echo "=== === === === === === === === === === ===" | tee -a compile.log
+		echo "" | tee -a compile.log
+		tail -c 5M compile.log | tee compile.log.temp
+        mv compile.log.temp compile.log
+	fi

+ 57 - 0
.config/surfingkeys/index.ts

@@ -0,0 +1,57 @@
+/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
+                             SurfingKeys Settings
+*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
+
+import { KeyMap } from "./src/objects/Keymap";
+import { Setting } from "./src/objects/Setting";
+import { SurfingkeysPerformanceMarks } from "./src/objects/SurfingkeysPerformanceMarks";
+
+(() => {
+  window.performance.mark(SurfingkeysPerformanceMarks.Started);
+  try {
+    api.Hints.setCharacters("arstneio");
+    api.map("n", "j");
+    api.map("e", "k");
+    api.map("i", "l");
+    api.map("h", "o");
+    new Setting("language", "en-US");
+    new Setting("startToShowEmoji", Infinity);
+    new Setting("tabsThreshold", 0);
+    new Setting("focusAfterClosed", "last");
+    new Setting("tabsMRUOrder", false);
+    new Setting("historyMUOrder", false);
+    new Setting("aceKeybindings", "vim");
+    new Setting("scrollStepSize", Math.pow(2, 8));
+    new Setting("omnibarMaxResults", Math.pow(2, 8));
+    new Setting("omnibarSuggestion", true);
+  } catch (err) {
+    console.error(err);
+    if (settings === undefined || api === undefined) {
+      alert("SurfingKeys was not loaded correctly! See console for details.");
+      return;
+    }
+    api.Front.showPopup(
+      '<span style="color: maroon; font-weight: bold;">SurfingKeys initialization error: </span>' +
+        err.toString(),
+    );
+  }
+  // Save init runtime to help menu via dummy keymap
+  new KeyMap(
+    " ",
+    () => {},
+    KeyMap.categories.help,
+    "Init took " +
+      (window.performance.mark(SurfingkeysPerformanceMarks.Initialized)
+        ? ""
+        : "") +
+      window.performance
+        .measure(
+          SurfingkeysPerformanceMarks.Measure,
+          SurfingkeysPerformanceMarks.Started,
+          SurfingkeysPerformanceMarks.Initialized,
+        )
+        .duration.toFixed(2)
+        .toString() +
+      "ms",
+  ).set();
+})();

+ 11 - 0
.config/surfingkeys/package.json

@@ -0,0 +1,11 @@
+{
+  "devDependencies": {
+    "esbuild": "~0.20",
+    "typescript": "~5"
+  },
+  "scripts": {
+    "dev": "npm run check && npm build",
+    "check": "tsc index.ts",
+    "build": "esbuild index.ts --bundle --platform=browser --tsconfig=tsconfig.json --analyze=verbose --outfile=index.js"
+  }
+}

+ 20 - 0
.config/surfingkeys/src/StyleLoadable.ts

@@ -0,0 +1,20 @@
+import { Theme } from "./objects/Theme";
+
+export class StyleLoadable {
+  load() {
+    new Theme(
+      // SurfingKeys Theme
+      // https://github.com/brookhong/Surfingkeys/tree/master/src/pages
+      ``,
+      // Custom Stylesheet
+      ``,
+      // Hint Style
+      // https://github.com/brookhong/Surfingkeys/blob/master/docs/API.md#hintsstyle
+      ``,
+      // Visual Style
+      // https://github.com/brookhong/Surfingkeys/blob/master/docs/API.md#visualstyle
+      ``,
+      ``,
+    ).set();
+  }
+}

+ 48 - 0
.config/surfingkeys/src/objects/Keymap.ts

@@ -0,0 +1,48 @@
+export class KeyMap {
+  key: string;
+  category: number;
+  command: any;
+  description: string;
+  static categories = {
+    help: 0,
+    mouseClick: 1,
+    scroll: 2,
+    tabs: 3,
+    pageNav: 4,
+    sessions: 5,
+    searchSelectedWith: 6,
+    clipboard: 7,
+    omnibar: 8,
+    visualMode: 9,
+    vimMarks: 10,
+    settings: 11,
+    chromeURLs: 12,
+    proxy: 13,
+    misc: 14,
+    insertMode: 15,
+  };
+  constructor(
+    key: string,
+    command: any,
+    category = KeyMap.categories.misc,
+    description = "",
+  ) {
+    this.key = key;
+    this.category = category;
+    this.description = description;
+    this.command = command;
+  }
+  get helpText() {
+    return "#" + this.category.toString() + this.description;
+  }
+  set() {
+    if (this.isReMap) {
+      api.map(this.key, this.command);
+    } else {
+      api.mapkey(this.key, this.helpText, this.command);
+    }
+  }
+  get isReMap() {
+    return typeof this.command === "string" || this.command instanceof String;
+  }
+}

+ 9 - 0
.config/surfingkeys/src/objects/Setting.ts

@@ -0,0 +1,9 @@
+export class Setting {
+  constructor(name, value) {
+    this.name = name;
+    this.value = value;
+  }
+  set() {
+    settings[this.name] = this.value;
+  }
+}

+ 5 - 0
.config/surfingkeys/src/objects/SurfingkeysPerformanceMarks.ts

@@ -0,0 +1,5 @@
+export const enum SurfingkeysPerformanceMarks {
+  Started = "SurfingKeysPerformanceStartedMark",
+  Initialized = "SurfingKeysPerformanceInitializedMark",
+  Measure = "SurfingKeysPerformanceMeasure",
+}

+ 26 - 0
.config/surfingkeys/src/objects/Theme.ts

@@ -0,0 +1,26 @@
+export class Theme {
+  constructor(theme, custom, hint, visualMarks, visualCursor) {
+    this.theme = theme;
+    this.custom = custom;
+    this.hint = hint;
+    this.visualMarks = visualMarks;
+    this.visualCursor = visualCursor;
+  }
+  set() {
+    // allow for custom styles for use in i.e. added elements
+    const customStylesheetId = "surfing-keys-custom-stylesheet";
+    if (document.getElementById(customStylesheetId) !== null) {
+      document.getElementById(customStylesheetId).remove();
+    }
+    const customStylesheet = document.createElement("style");
+    customStylesheet.innerHTML = this.custom;
+    customStylesheet.setAttribute("id", customStylesheetId);
+    document.head.appendChild(customStylesheet);
+
+    // set SurfingKeys-specific styles via API
+    new Setting("theme", this.theme).set();
+    api.Hints.style(this.hint);
+    api.Visual.style("marks", this.visualMarks);
+    api.Visual.style("cursor", this.visualCursor);
+  }
+}

+ 14 - 0
.config/surfingkeys/tsconfig.json

@@ -0,0 +1,14 @@
+{
+  "compilerOptions": {
+    "target": "es2022",
+    "module": "commonjs",
+    "esModuleInterop": true,
+    "forceConsistentCasingInFileNames": true,
+    "strict": true,
+    "noImplicitAny": true,
+    "strictNullChecks": true,
+    "alwaysStrict": true,
+    "noUnusedLocals": false,
+    "noUnusedParameters": false
+  }
+}

+ 6 - 0
.github/README.md

@@ -64,6 +64,12 @@ Standalone shell scripts to be called by other programs.
 Configuration for [skdh](https://github.com/koekeishiya/skhd), a simple hotkey
 Configuration for [skdh](https://github.com/koekeishiya/skhd), a simple hotkey
 daemon for macOS.
 daemon for macOS.
 
 
+### [surfingkeys (`~/.config/surfingkeys/`)](./.config/surfingkeys/)
+
+Configuration for [Surfingkeys](https://github.com/brookhong/Surfingkeys), a web
+browser extension that provides control of the web in the spirit of Vim. See the
+subdirectory's [README.md](./.config/surfingkeys/README.md) for details.
+
 ### [tmux (`~/.config/tmux/`)](./.config/tmux/)
 ### [tmux (`~/.config/tmux/`)](./.config/tmux/)
 
 
 Configuration for [tmux](https://github.com/tmux/tmux), a terminal multiplexer.
 Configuration for [tmux](https://github.com/tmux/tmux), a terminal multiplexer.