diff --git a/README.md b/README.md index 7cb49488..27cc084b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,4 @@

- OSX - Icon made by Freepik from Flaticon - Linux - Icon made by Freepik from Flaticon - Android - Icon made by Freepik from Flaticon denisidoro/dotfiles @@ -13,7 +10,7 @@ Awesome personal dotfiles

- Installation    + Installation    Shell    Scripts    Git    @@ -43,7 +40,7 @@ git clone https://github.com/denisidoro/dotfiles "$DOTFILES" ```bash dot::clone() { - DOT_VERSION=master bash <(curl -s https://raw.githubusercontent.com/denisidoro/dotfiles/master/scripts/self/install) + bash <(curl -s https://raw.githubusercontent.com/denisidoro/dotfiles/master/scripts/self/install) } dot::clone_if_necessary() { @@ -83,17 +80,6 @@ Benchmark #1: /usr/bin/time /bin/zsh -i -c exit Range (min … max): 32.7 ms … 48.8 ms 67 runs ``` -## Overriding configs - -Edit the following files accordingly: -```bash -# shell -vi "${DOTFILES}/local/zshrc" - -# git -vi "${DOTFILES}/local/gitconfig" -``` - ## Template In order to setup your own dotfiles, I recommend using [dotly](https://github.com/CodelyTV/dotly) or [Sloth](https://github.com/gtrabanco/.Sloth), which are frameworks inpired by this repository. diff --git a/bin/dot b/bin/dot index 6a56115e..6c20eccf 100755 --- a/bin/dot +++ b/bin/dot @@ -54,8 +54,9 @@ _alias() { bash|sh|shell|terminal|scripting) echo script ;; fs) echo filesystem ;; and) echo android ;; + cloud) echo storm ;; clj) echo clojure ;; - game) echo gaming ;; + gaming) echo game ;; environment|env) echo self ;; net) echo network ;; pkg) echo package ;; @@ -98,7 +99,7 @@ elif [[ $# -eq 1 ]]; then echo 'Commands:' for cmd in $(find "${DOTFILES}/scripts/${context_query}/" -mindepth 1 -maxdepth 1 -executable -type f | awk -F"/" '{print $NF}'); do - printf " %-24s %s" "$cmd" "$("${DOTFILES}/scripts/${context_query}/${cmd}" --help | head -n1)" + printf " \033[34m%-24s\033[39m \033[37m%s\033[39m" "$cmd" "$("${DOTFILES}/scripts/${context_query}/${cmd}" --help | head -n1)" echo done else diff --git a/bin/e b/bin/e new file mode 100755 index 00000000..dfd87b06 --- /dev/null +++ b/bin/e @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +dot_bin_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" + +editors="/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code,code,vscode,sublime,nvim,vim,vi,nano" +"${dot_bin_dir}/dot" terminal dashed "$editors" -- "$@" diff --git a/bin/git-dot b/bin/git-dot index f88ef712..8760b282 100755 --- a/bin/git-dot +++ b/bin/git-dot @@ -2,4 +2,5 @@ set -euo pipefail dot_bin_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" + "${dot_bin_dir}/dot" git "$@" \ No newline at end of file diff --git a/bin/v b/bin/v new file mode 100755 index 00000000..dc4de332 --- /dev/null +++ b/bin/v @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +dot_bin_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" + +editors="nvim,vim,vi,nano" +"${dot_bin_dir}/dot" terminal dashed "$editors" -- "$@" diff --git a/browsers/vivaldi/common.css b/browsers/vivaldi/common.css deleted file mode 100644 index f4378beb..00000000 --- a/browsers/vivaldi/common.css +++ /dev/null @@ -1,16 +0,0 @@ -.win #tabs-container .tab:not(.pinned):not(.tab-small).audio-on .tab-audio, -.linux:not(.alt) #tabs-container .tab:not(.pinned):not(.tab-small).audio-on .tab-audio, -.win #tabs-container .tab:not(.pinned):not(.tab-small).audio-muted .tab-audio, -.linux:not(.alt) #tabs-container .tab:not(.pinned):not(.tab-small).audio-muted .tab-audio, -.win #tabs-container .tab:not(.pinned):not(.tab-small).tab-captured .tab-audio, -.linux:not(.alt) #tabs-container .tab:not(.pinned):not(.tab-small).tab-captured .tab-audio { - transform: scale(0) !important; -} -.win #tabs-container .tab:not(.pinned):not(.tab-small).audio-on .favicon, -.linux:not(.alt) #tabs-container .tab:not(.pinned):not(.tab-small).audio-on .favicon, -.win #tabs-container .tab:not(.pinned):not(.tab-small).audio-muted .favicon, -.linux:not(.alt) #tabs-container .tab:not(.pinned):not(.tab-small).audio-muted .favicon, -.win #tabs-container .tab:not(.pinned):not(.tab-small).tab-captured .favicon, -.linux:not(.alt) #tabs-container .tab:not(.pinned):not(.tab-small).tab-captured .favicon { - transform: scale(1) !important; -} \ No newline at end of file diff --git a/config.yaml b/config.yaml new file mode 100644 index 00000000..67024928 --- /dev/null +++ b/config.yaml @@ -0,0 +1,7 @@ +pkg: + sudo: + apk: true + +game: + cemu: + dir: /mnt/d/Emulators/Cemu \ No newline at end of file diff --git a/editors/spacevim/spacevim.rc b/editors/spacevim/spacevim.rc index cf5380e1..2ff03983 100644 --- a/editors/spacevim/spacevim.rc +++ b/editors/spacevim/spacevim.rc @@ -1,3 +1,5 @@ +let g:go_version_warning = 0 + let g:spacevim_plug_home = '~/.vim/plugged' " let g:spacevim_leader = "<\Space>" @@ -22,7 +24,7 @@ function! UserInit() Plug 'junegunn/seoul256.vim' Plug 'airblade/vim-rooter' Plug 'danilo-augusto/vim-afterglow' - Plug 'liuchengxu/space-vim-dark' + " Plug 'liuchengxu/space-vim-dark' Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' } endfunction @@ -39,7 +41,7 @@ function! UserConfig() if has('termguicolors') " colorscheme afterglow - colorscheme space-vim-dark + " colorscheme space-vim-dark hi Comment cterm=italic hi Normal ctermbg=NONE guibg=NONE hi LineNr ctermbg=NONE guibg=NONE diff --git a/editors/vscode/settings.json b/editors/vscode/settings.json index cb57e4ec..bb7bc911 100644 --- a/editors/vscode/settings.json +++ b/editors/vscode/settings.json @@ -44,7 +44,7 @@ "terminal.integrated.rendererType": "dom", // ================== // Explorer - // ================== + // ================== "explorer.confirmDragAndDrop": false, "explorer.confirmDelete": false, "files.exclude": { @@ -93,11 +93,11 @@ // }, // ================== // Rust - // ================== + // ================== "rust-analyzer.checkOnSave.command": "clippy", // ================== // Javascript - // ================== + // ================== "javascript.validate.enable": false, "javascript.updateImportsOnFileMove.enabled": "always", // ================== @@ -230,4 +230,4 @@ "typescript.inlayHints.propertyDeclarationTypes.enabled": true, "typescript.inlayHints.variableTypes.enabled": true, "workbench.editor.enablePreviewFromCodeNavigation": true -} \ No newline at end of file +} diff --git a/git/config b/git/config index 1bb84526..b7e1e41f 100644 --- a/git/config +++ b/git/config @@ -86,7 +86,7 @@ autoStash = true [include] - path = ~/dotfiles/local/gitconfig + path = ~/dotfiles/local/mac/gitconfig [pull] rebase = true diff --git a/navi/cheats/android.cheat b/navi/cheats/android.cheat index de26d4f7..26b493d7 100644 --- a/navi/cheats/android.cheat +++ b/navi/cheats/android.cheat @@ -32,4 +32,4 @@ $ ssh_config: echo "${PREFIX}/etc/ssh/sshd_config" % android, apps # Open Google Play Store profile page for an app -dot browser google-lucky " site:play.google.com" +dot terminal open "https://duckduckgo.com/?q=%21+$(dot script eval --load str str::urlencode " site:play.google.com")&ia=web" diff --git a/navi/cheats/editor.cheat b/navi/cheats/editor.cheat index eea61917..9f263eb9 100644 --- a/navi/cheats/editor.cheat +++ b/navi/cheats/editor.cheat @@ -4,6 +4,6 @@ echo "" # Edit dotfiles in VSCode -dot terminal dashed dot code vscode -- "${DOTFILES}" &disown +e "${DOTFILES}" &disown $ vscode_action: curl -sL "https://raw.githubusercontent.com/aburok/mysettings/master/VisualStudio/vscommands.txt" diff --git a/navi/cheats/filesystem.cheat b/navi/cheats/filesystem.cheat index 2710d6ee..dd823f9b 100644 --- a/navi/cheats/filesystem.cheat +++ b/navi/cheats/filesystem.cheat @@ -7,7 +7,7 @@ find -L . -name . -o -type d -prune -o -type l -exec rm {} + du -sh # Edit fre entries -dot code vscode "${HOME}/Library/Application Support/fre/fre.json" +e "${HOME}/Library/Application Support/fre/fre.json" # Resize pngs to 128x128 \ls ./*[^(_128)].png | sed 's/.png//' | xargs -I% convert "%.png" -resize 128x128 "%_128.png" \ No newline at end of file diff --git a/navi/cheats/tmp.cheat b/navi/cheats/tmp.cheat index 76b1bef0..04accdb1 100644 --- a/navi/cheats/tmp.cheat +++ b/navi/cheats/tmp.cheat @@ -1,3 +1,13 @@ +% examples +# Display contents of a file +cat + +# Echo text +echo + +$file: ls + + % tmp # Echo multiline @@ -61,6 +71,13 @@ $ log: echo "foo bar" $ words: echo "$log" | wc -w | xargs +% empty + +# empty test +tar -xf + +$ file: ls *.tar + % default # default test diff --git a/raycast/navi.sh b/raycast/navi.sh index 5225fe3d..aaba5b9d 100755 --- a/raycast/navi.sh +++ b/raycast/navi.sh @@ -6,7 +6,7 @@ # @raycast.mode silent # Optional parameters: -# @raycast.icon /Users/denis.isidoro/Pictures/Icons/navi_128.png +# @raycast.icon /Users/denis.isidoro/Pictures/Icons/navi_64sq.png # @raycast.packageName Browser # Documentation: diff --git a/repos/dotlink/set.sh b/repos/dotlink/set.sh index 8a583527..1e136d45 100644 --- a/repos/dotlink/set.sh +++ b/repos/dotlink/set.sh @@ -9,13 +9,14 @@ dot_set() { local dotset_backup=false local dotset_verbose=false + # TODO: understand why doset_backup=true is necessary here for arg in "$@"; do shift case "$arg" in "--ignore" ) set -- "$@" "-i" ;; "--force" ) set -- "$@" "-f" ;; "--create-dirs"|"p" ) dotset_create_dirs=true ;; - "--backup" ) set -- "$@" "-b" ;; + "--backup" ) dotset_backup=true; set -- "$@" "-b" ;; "--verbose") set -- "$@" "-v" ;; *) set -- "$@" "$arg" ;; esac @@ -32,6 +33,12 @@ dot_set() { esac done + # echo "args: $*" >&2 + # echo "dotset_ignore: ${dotset_ignore:-}" >&2 + # echo "dotset_force: ${dotset_force:-}" >&2 + # echo "dotset_backup: ${dotset_backup:-}" >&2 + # echo "dotset_verbose: ${dotset_verbose:-}" >&2 + check_dir() { #{{{ local orig="$1" @@ -160,6 +167,16 @@ dot_set() { dotfile="$1" orig="$2" + if [ -n "${DOTLINK_IGNORE_LIST:-}" ]; then + IFS=',' read -r -a ignores <<< "$DOTLINK_IGNORE_LIST" + for ignore in "${ignores[@]}"; do + if [[ "$dotfile" = *"$ignore"* ]]; then + echo "IGNORING ${dotfile} because it matches ${ignore}!" + return 0 + fi + done + fi + # if dotfile doesn't exist, print error message and pass if [ ! -e "${dotfile}" ]; then echo "$(prmpt 1 "not found")${dotfile}" diff --git a/repos/jira-epic/index.js b/repos/jira-epic/index.js deleted file mode 100644 index 4215be10..00000000 --- a/repos/jira-epic/index.js +++ /dev/null @@ -1,50 +0,0 @@ -const fs = require("fs"); -const stdinBuffer = fs.readFileSync(0); -main(stdinBuffer.toString()); - -function main(json) { - const rawIssues = JSON.parse(json).rss.channel.item - - const issues = rawIssues.map(issue => { - const id = issue.key['$t']; - const summary = issue.summary; - const links = issue.issuelinks?.issuelinktype; - const outward = asLink(links?.outwardlinks); - const status = issue.status['$t'] - const isClosed = status == 'Closed' - - return { - summary, - id, - outward, - isClosed - } - }) - - console.log("digraph graphname{") - - issues.forEach(({ summary, id, isClosed }) => { - const extra = isClosed ? " fillcolor=green style=filled" : "" - console.log(` "${id}"[label="${summary}"${extra}]`) - }) - - console.log("") - - issues.forEach(({ id, outward }) => { - if (outward?.target) { - console.log(` "${id}"->"${outward.target}" [label="${outward.description}"]`) - } - }) - - console.log("}") -} - -function asLink(x) { - if (x == null || x == undefined) { - return null - } - return { - description: x.description, - target: (x.issuelink?.issuekey || {})['$t'] - } -} \ No newline at end of file diff --git a/repos/tasker-js/.gitignore b/repos/tasker-js/.gitignore deleted file mode 100644 index 77738287..00000000 --- a/repos/tasker-js/.gitignore +++ /dev/null @@ -1 +0,0 @@ -dist/ \ No newline at end of file diff --git a/repos/tasker-js/Makefile b/repos/tasker-js/Makefile deleted file mode 100644 index 246c595b..00000000 --- a/repos/tasker-js/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -.PHONY: all test clean - -test: src/ test/ - ./scripts/install - ./scripts/proxy test - -run: src/ - ./scripts/install - ./scripts/proxy run \ No newline at end of file diff --git a/repos/tasker-js/babel.config.json b/repos/tasker-js/babel.config.json deleted file mode 100644 index fea7004c..00000000 --- a/repos/tasker-js/babel.config.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "presets": [ - [ - "@babel/preset-env", - { - "targets": { - "esmodules": true, - "node": "current" - } - } - ] - ] -} \ No newline at end of file diff --git a/repos/tasker-js/package.json b/repos/tasker-js/package.json deleted file mode 100644 index 8c050fe7..00000000 --- a/repos/tasker-js/package.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "taskerjs", - "version": "1.0.0", - "description": "", - "main": "src/main.js", - "author": "", - "license": "ISC", - "files": [ - "src" - ], - "types": "dist/index.d.ts", - "scripts": { - "lint": "eslint . --ext .ts,.tsx", - "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register 'test/**/*.ts'", - "watch": "watch 'npm run build && npm run push' src/", - "start": "webpack --mode development" - }, - "devDependencies": { - "@babel/cli": "^7.0.0", - "@babel/core": "^7.14.3", - "@babel/node": "^7.14.2", - "@babel/preset-env": "^7.14.2", - "@types/mocha": "^8.2.2", - "@typescript-eslint/eslint-plugin": "^4.27.0", - "@typescript-eslint/parser": "^4.27.0", - "eslint": "^7.29.0", - "mocha": "^9.0.1", - "ts-node": "^10.0.0", - "typescript": "^4.3.4", - "watch": "^1.0.2", - "webpack": "^5.38.1", - "webpack-cli": "^4.7.0" - }, - "dependencies": { - "awesome-typescript-loader": "^5.2.1", - "source-map-loader": "^3.0.0" - } -} diff --git a/repos/tasker-js/scripts/compile b/repos/tasker-js/scripts/compile deleted file mode 100755 index 3b24fb88..00000000 --- a/repos/tasker-js/scripts/compile +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -source "$(dirname "$0")/core.sh" - -OUTPUT="${PROJ_HOME}/dist/bundle.js" - -cd "$PROJ_HOME" -webpack --mode development - -cat "$OUTPUT" | pbcopy diff --git a/repos/tasker-js/scripts/core.sh b/repos/tasker-js/scripts/core.sh deleted file mode 100755 index b5f5adca..00000000 --- a/repos/tasker-js/scripts/core.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash - -npm::cmd() { - if has yarn; then - echo yarn - return 0 - elif has npm; then - echo npm - return 0 - fi - - dot pkg add yarn - echo yarn -} - -dot::clone() { - local -r DOTFILES_COMMIT_HASH="e517c25" - git clone "https://github.com/denisidoro/dotfiles.git" "$DOTFILES" - cd "$DOTFILES" || exit - git checkout "$DOTFILES_COMMIT_HASH" -} - -dot::install_if_necessary() { - [ -n "${DOTFILES:-}" ] && [ -x "${DOTFILES}/bin/dot" ] && return - export DOTFILES="${PROJ_HOME}/dotfiles" - export PATH="${DOTFILES}/bin:${PATH}" - [ -n "${DOTFILES:-}" ] && [ -x "${DOTFILES}/bin/dot" ] && return - dot::clone 2>/dev/null || true -} - -export PROJ_HOME="${PROJ_HOME:-$(cd "$(dirname "$0")/.." && pwd)}" -export PROJ_NAME="klapaucius" - -klap() { - local -r fn="$1" - shift - "${PROJ_HOME}/scripts/${fn}" "$@" -} - -export -f klap - -dot::install_if_necessary -source "${DOTFILES}/scripts/core/main.sh" \ No newline at end of file diff --git a/repos/tasker-js/scripts/fix b/repos/tasker-js/scripts/fix deleted file mode 100755 index e4c50116..00000000 --- a/repos/tasker-js/scripts/fix +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -source "$(dirname "$0")/core.sh" - -cd "$PROJ_HOME" -npx eslint 'src/**' --fix \ No newline at end of file diff --git a/repos/tasker-js/scripts/install b/repos/tasker-js/scripts/install deleted file mode 100755 index df9f12cd..00000000 --- a/repos/tasker-js/scripts/install +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -source "$(dirname "$0")/core.sh" - -main() { - if [ -d "${PROJ_HOME}/node_modules" ]; then - : - else - "${PROJ_HOME}/scripts/proxy" install - fi -} - -main "$@" \ No newline at end of file diff --git a/repos/tasker-js/scripts/proxy b/repos/tasker-js/scripts/proxy deleted file mode 100755 index c545570e..00000000 --- a/repos/tasker-js/scripts/proxy +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -source "$(dirname "$0")/core.sh" - -main() { - local -r npm="$(npm::cmd)" - cd "$PROJ_HOME" - $npm "$@" -} - -main "$@" \ No newline at end of file diff --git a/repos/tasker-js/src/db.ts b/repos/tasker-js/src/db.ts deleted file mode 100644 index a4520951..00000000 --- a/repos/tasker-js/src/db.ts +++ /dev/null @@ -1,340 +0,0 @@ -export type Id = number -export type Path = string -export type Filename = string -export type Size = number -export type Date6 = number - -export interface FsFolder { - id: Id, - name: string, - parent: Id -} - -export interface FsFile { - id: Id, - name: string, - folder: Id - kb: number, - date: number -} - -export interface TelegramUpload { - id: Id, - fileId: Id, -} - -export interface AzureFile { - id: Id, - name: string, - folder: Id, - files: Id[] -} - -export interface Data { - fs: { folders: FsFolder[], files: FsFile[] }, - telegram: { uploads: TelegramUpload[] }, - azure: { files: AzureFile[] } -} - -function asInt(x: any): number { - return parseInt(x) -} - -function asStr(x: any): string { - return x.toString() -} - -function asIntVec(x: any): number[] { - return x.toString().split(";").map(asInt) -} - -function withoutLeadingSlash(path: string): string { - if (path[0] === "/") return path.substring(1) - return path -} - -function withZip(path: any): string { - return `${path}.7z` -} - -function nullOrUndefined(x: any): boolean { - return (x === null || x === undefined) -} - -function getProp(data: Data, name: string): any[] | undefined { - let xs = data - for (const p of name.split(".")) { - xs = xs[p] - if (!xs) break - } - // @ts-ignore - return xs -} - -const transformers: { [key: string]: [string, (arg: any) => any][] } = { - "fs.folders": [ - ["id", asInt], - ["name", asStr], - ["parent", asInt] - ], - "fs.files": [ - ["id", asInt], - ["name", asStr], - ["folder", asInt], - ["kb", asInt], - ["date", asInt], - ], - "telegram.uploads": [ - ["id", asInt], - ["fileId", asStr], - ], - "azure.files": [ - ["id", asInt], - ["name", asStr], - ["folder", asInt], - ["files", asIntVec] - ], -} - -export class Db { - - data: Data - - constructor(txt: string) { - this.data = { - fs: { - folders: [], - files: [] - }, - telegram: { - uploads: [] - }, - azure: { - files: [] - } - } - - let ctx = null - txt.split("\n").forEach((line: string) => { - if (line[0] === "[") { - ctx = line.substring(1, line.length - 1) - return - } - const ps = line.split(",") - if (ps[0] === "") { - return - } - const transformer = transformers[ctx] - const x = {} - for (let i = 0; i < transformer.length; i++) { - const [name, fn] = transformer[i] - const value = ps[i] - const isEmpty = (value === null || value === undefined || value === "") - if (!isEmpty) { - x[name] = fn(value) - } - } - let v = this.data - ctx.split(".").forEach((p: string | number) => { - v = v[p] - }) - // @ts-ignore - v.push(x) - }) - } - - serialize(): string { - let out = "" - - for (const [name, keys] of Object.entries(transformers)) { - out = `${out}[${name}]\n` - const xs = getProp(this.data, name) - if (!xs) continue - - xs.forEach(x => { - const ps = [] - keys.forEach(([k, fn]) => { - const value = nullOrUndefined(x[k]) ? "" : x[k] - const valueStr = fn === asIntVec ? value.join(";") : value.toString() - ps.push(valueStr) - }) - out = `${out}${ps.join(",")}\n` - }) - out = `${out}\n` - } - - return out - } - - fsFolderFullPath(id: Id): Path { - let path = "" - let folder = null - while (true) { - if (folder != null) { - id = folder.parent - } - if (id === 0) { - break - } - folder = this.data.fs.folders.find((x) => x.id === id) - path = `${folder.name}/${path}` - } - return path - } - - fsFileFullPath(id: Id): Path { - const file = this.data.fs.files.find((x) => x.id === id) - const folderPath = this.fsFolderFullPath(file.folder) - return `${folderPath}${file.name}` - } - - fsFolderNextId(): Id { - return this.data.fs.folders.length + 1 - } - - fsFileNextId(): Id { - return this.data.fs.files.length - } - - azureFileNextId(): Id { - return this.data.azure.files.length - } - - fsFileFind(path: Path): FsFile | undefined { - path = withoutLeadingSlash(path) - const [filename, ...dirsRev] = path.split("/").reverse() - let folder = { - id: 0 - } - for (const p of dirsRev.reverse()) { - // console.log({folder}) - folder = this.data.fs.folders.find((x) => (x.name === p || withZip(x.name) === p) && x.parent === folder.id) - if (!folder) break - } - - if (!folder) return null - - return this.data.fs.files.find((x) => x.name === filename && x.folder === folder.id) - } - - fsFileFindOrCreate(path: Path): FsFile { - return this.fsFileFind(path) || this.fsFileAdd(path, null, null) - } - - fsFolderAdd(path: Path): { folder: FsFolder, filename: Filename } { - path = withoutLeadingSlash(path) - - let parent = { - id: 0, - name: "", - parent: 0 - } - - const [filename, ...dirsRev] = path.split("/").reverse() - dirsRev.reverse().forEach((p: any) => { - const existingFolder = this.data.fs.folders.find((x) => x.name === p && x.parent === parent.id) - if (existingFolder) { - parent = existingFolder - } else { - const id = this.fsFolderNextId() - const folder = { - id, - name: p, - parent: parent.id - } - this.data.fs.folders.push(folder) - parent = folder - } - }) - - return { - folder: parent, - filename - } - } - - fsFileAdd(path: Path, kb: Size, date: Date6): FsFile { - path = withoutLeadingSlash(path) - const addFolderRes = this.fsFolderAdd(path) - const filename = addFolderRes.filename - const parent = addFolderRes.folder - const existingFile = this.data.fs.files.find((x) => (x.name === filename || withZip(x.name) === filename) && x.folder === parent.id) - if (existingFile) return existingFile - const id = this.fsFileNextId() - const file = { - id, - name: filename, - folder: parent.id, - kb, - date - } - this.data.fs.files.push(file) - return file - } - - telegramUploadFind(path: Path): TelegramUpload | undefined { - const file = this.fsFileFind(path) - if (!file) return null - const id = file.id - return this.data.telegram.uploads.find((x) => x.id === id) - } - - telegramUploadAdd(path: Path, fileId: Id, thumbId: Id): TelegramUpload { - const file = this.fsFileFindOrCreate(path) - const id = file.id - const upload = { - id, - fileId, - thumbId - } - - const idx = this.data.telegram.uploads.findIndex((x) => x.id === id) - if (idx >= 0) { - this.data.telegram.uploads[idx] = upload - } else { - this.data.telegram.uploads.push(upload) - } - - return upload - } - - azureFileAdd(path: Path, filePaths: Array): AzureFile { - const { - folder, - filename - } = this.fsFolderAdd(path) - - const existingFile = this.data.azure.files.find((x) => x.name === filename && x.folder === folder.id) - if (existingFile) return - - const fileIds = [] - for (const filePath of filePaths) { - const file = this.fsFileFindOrCreate(filePath) - fileIds.push(file.id) - } - - const id = this.azureFileNextId() - const file = { - id, - name: filename, - folder: folder.id, - files: fileIds - } - - this.data.azure.files.push(file) - - return file - } - - azurePathsNotUploaded(): Path[] { - const uploadedSet = new Set() - for (const file of this.data.azure.files) { - for (const id of file.files) { - uploadedSet.add(id) - } - } - const all = this.data.fs.files.map((x) => x.id) - const diff = all.filter((x) => !uploadedSet.has(x)) - return diff.map((id) => this.fsFileFullPath(id)) - } -} diff --git a/repos/tasker-js/src/main.ts b/repos/tasker-js/src/main.ts deleted file mode 100644 index b7a72f8e..00000000 --- a/repos/tasker-js/src/main.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Db } from "./db" - -const txt = `TODO` - -const db = new Db(txt) - -const files = db.data.fs.files; -files.forEach(file => { - const id = file.id - const path = db.fsFileFullPath(id) - console.log(`${path};${id};${file.kb};${file.date}`) -}) diff --git a/repos/tasker-js/test/db.ts b/repos/tasker-js/test/db.ts deleted file mode 100644 index dc7b6d78..00000000 --- a/repos/tasker-js/test/db.ts +++ /dev/null @@ -1,84 +0,0 @@ -import assert = require('assert'); -import { Db } from '../src/db' - -const txt = ` -[fs.folders] -1,Pictures,0 -2,DCIM,1 -3,Games,0 - -[fs.files] -0,img00.jpg,2 -1,gta.sav,3 - -[telegram.uploads] -0,123,456 -1,987,765 - -[azure.files] -0,witcher.sav,3,0;1 -` - -const out = ` -[fs.folders] -1,Pictures,0 -2,DCIM,1 -3,Games,0 -4,Books,0 -5,Fiction,4 -6,German,4 -7,Documents,0 -8,ID,7 - -[fs.files] -0,img00.jpg,2,, -1,gta.sav,3,, -2,img01.jpg,2,323,150630 -3,LotR2.pdf,5,1123,181203 -4,img01b.jpg,2,, -5,img03.jpg,2,, -6,nein.pdf,6,, -7,rg.jpg,8,, -8,titre.jpg,8,, - -[telegram.uploads] -0,123 -1,987 -2,666 -4,666 -7,666 -8,666 - -[azure.files] -0,witcher.sav,3,0;1 -1,blob.rar,4,2;5;3;6` - -describe('Db', () => { - it('idempotency', () => { - const db = new Db(txt) - const db2 = new Db(db.serialize()) - const db3 = new Db(db2.serialize()) - assert.deepStrictEqual(db3.serialize().trim(), db.serialize().trim()) - }); - - it('integration test', () => { - const db = new Db(txt) - db.fsFileAdd("Pictures/DCIM/img01.jpg", 323, 150630) - db.fsFileAdd("Books/Fiction/LotR2.pdf", 1123, 181203) - db.fsFileAdd("Books/Fiction/LotR2.pdf", 1123, 181203) - db.telegramUploadAdd("Pictures/DCIM/img01.jpg.7z", 666, 777) - db.telegramUploadAdd("/Pictures/DCIM/img01.jpg", 666, 777) - db.telegramUploadAdd("/Pictures/DCIM/img01b.jpg", 666, 777) - db.azureFileAdd("/Books/blob.rar", ["Pictures/DCIM/img01.jpg.7z", "Pictures/DCIM/img03.jpg", "/Books/Fiction/LotR2.pdf", "Books/German/nein.pdf"]) - db.telegramUploadAdd("/Documents/ID/rg.jpg", 666, 777) - db.telegramUploadAdd("/Documents/ID/titre.jpg", 666, 777) - - assert.deepStrictEqual(db.azurePathsNotUploaded(), [ - 'Pictures/DCIM/img01b.jpg', - 'Documents/ID/rg.jpg', - 'Documents/ID/titre.jpg' - ]) - - assert.deepStrictEqual(db.serialize().trim(), out.trim()) - }); -}); \ No newline at end of file diff --git a/repos/tasker-js/tsconfig.json b/repos/tasker-js/tsconfig.json deleted file mode 100644 index fda26dbb..00000000 --- a/repos/tasker-js/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "downlevelIteration": true, - "rootDir": "./src", - "allowJs": true, - "declaration": true, - "outDir": "./dist", - "alwaysStrict": false, - "lib": [ - "esnext" - ], - "experimentalDecorators": true, - "baseUrl": "./" - }, - "include": [ - "./src/**/*" - ] -} \ No newline at end of file diff --git a/repos/tasker-js/webpack.config.js b/repos/tasker-js/webpack.config.js deleted file mode 100644 index 7c63dd59..00000000 --- a/repos/tasker-js/webpack.config.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - devtool: 'inline-source-map', - entry: './src/main.ts', - output: { - filename: 'bundle.js', - path: `${__dirname}/dist`, - }, - resolve: { - extensions: ['.ts', '.js'] - }, - module: { - rules: [ - { test: /\.ts?$/, loader: 'awesome-typescript-loader' }, - ], - }, - plugins: [ - ] -}; \ No newline at end of file diff --git a/scripts/book/cover b/scripts/book/cover deleted file mode 100755 index 87a01078..00000000 --- a/scripts/book/cover +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash -set -uo pipefail - -source "${DOTFILES}/scripts/core/main.sh" -source "${DOTFILES}/scripts/core/str.sh" - -##? Gets cover for books -##? -##? Usage: -##? cover [options] -##? -##? Options: -##? -d --display Show image instead of printing the URL -##? -z --zoom Zoom level [default: 0] - -doc::parse "$@" - -get_json() { - local -r query="$(str::urlencode "$1")" - - curl -s \ - "https://www.googleapis.com/books/v1/volumes?q=$query" \ - -H 'Accept: application/json, text/javascript, */*; q=0.01' \ - -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' \ - -H 'DNT: 1' -} - -thumbnail() { - jq -r '.items | first | .volumeInfo.imageLinks.thumbnail' -} - -big() { - sed "s/oom=1/oom=${zoom}/g" -} - -url="$(get_json "$query" | thumbnail | big)" - -if $display; then - wget -qO- "$url" | imgcat -else - echo "$url" -fi diff --git a/scripts/browser/google-lucky b/scripts/browser/google-lucky deleted file mode 100755 index 1bfdd508..00000000 --- a/scripts/browser/google-lucky +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -source "${DOTFILES}/scripts/core/main.sh" -source "${DOTFILES}/scripts/core/str.sh" - -##? Opens a webpage directly via DuckDuckGo's "feeling lucky" -##? -##? Usage: -##? google-lucky - -doc::parse "$@" - -url="https://duckduckgo.com/?q=%21+$(str::urlencode "$query")&ia=web" -dot terminal open "$url" diff --git a/scripts/channel/handle b/scripts/channel/handle new file mode 100755 index 00000000..d4c1e0c2 --- /dev/null +++ b/scripts/channel/handle @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/core/main.sh" + +##? Handle a channel message +##? +##? Usage: +##? handle [] +##? +##? Examples: +##? handle url https://google.com + +doc::maybe_help "$@" + +_log() { + local -r file="${DOTFILES}/local/channel_log.txt" + if [ -f "$file" ]; then + touch "$file" + fi + echo "$(date +"%Y-%m-%d %H:%M:%S") $*" >> "$file" +} + +main() { + _log "$@" + + local -r type="$1" + shift + + case "$type" in + url|uri) + open "$@" + ;; + not|notify|notification) + # set -f + # args=(${*//;/ }) + IFS=';' read -r -a args <<< "$*" + dot channel notify "${args[@]}" + ;; + clip) + if [ -n "$*" ]; then + echo "$*" | dot script clip copy + else + local -r clip="$(dot script clip paste)" + dot telegram message "$clip" + fi + ;; + say) + osascript -e "say \"$*\"" + ;; + rickroll) + open "https://www.youtube.com/watch?v=dQw4w9WgXcQ" + ;; + *) + die "unknown type: $type" + ;; + esac +} + +main "$@" \ No newline at end of file diff --git a/scripts/channel/notify b/scripts/channel/notify new file mode 100755 index 00000000..cfe0f580 --- /dev/null +++ b/scripts/channel/notify @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/core/main.sh" + +##? Shows a system notification +##? +##? Usage: +##? notify [] [<subtitle>] + +doc::maybe_help "$@" + +main() { + local -r message="$1" + local -r title="${2:-}" + local -r subtitle="${3:-}" + + local code="display notification \"${message}\"" + if [ -n "$title" ]; then + code="${code} with title \"${title}\"" + fi + if [ -n "$subtitle" ]; then + code="${code} subtitle \"${subtitle}\"" + fi + + afplay "/System/Library/Sounds/Glass.aiff" & + osascript -e "$code" +} + +main "$@" \ No newline at end of file diff --git a/scripts/share/channel b/scripts/channel/send similarity index 92% rename from scripts/share/channel rename to scripts/channel/send index cf657d9f..fab3f1c5 100755 --- a/scripts/share/channel +++ b/scripts/channel/send @@ -6,10 +6,10 @@ source "${DOTFILES}/scripts/core/main.sh" ##? Sends a message to a channel ##? ##? Usage: -##? channel <target> <type> [<data>] +##? send <target> <type> [<data>] ##? ##? Examples: -##? channel phone app BubbleUPnP +##? send phone app BubbleUPnP doc::maybe_help "$@" diff --git a/scripts/code/vscode b/scripts/code/vscode deleted file mode 100755 index 7dcf1b0b..00000000 --- a/scripts/code/vscode +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -source "${DOTFILES}/scripts/core/main.sh" - -##? VSCode helpers -##? -##? Usage: -##? vscode - -doc::maybe_help "$@" - -_code() { - local target="${1:-$PWD}" - [[ "$target" == "." ]] && target="$PWD" - [[ "$target" == "$HOME" ]] && echoerr "Can't open the whole home dir in VSCode" && return 1 - - # local full_target - # [[ "$target" == /* ]] && full_target="$target" || full_target="${PWD}/${target}" - - # local cwd - # [[ -d "$full_target" ]] && cwd="$full_target" || cwd="$(dirname "$full_target")" - - # export VSCODE_CWD="$cwd" - # export APP_ROOT="$cwd" - - [[ $# -gt 0 ]] && shift - - local -r java_home=$(/usr/libexec/java_home -v 14) - export JAVA_HOME="$java_home" - - local -r osx_path="/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code" - if [ -f "$osx_path" ]; then - "$osx_path" "$target" "$@" - else - command code "$target" "$@" - fi -} - -_code "$@" diff --git a/scripts/core/main.sh b/scripts/core/main.sh index 2aad18dd..66b9a59c 100644 --- a/scripts/core/main.sh +++ b/scripts/core/main.sh @@ -1,5 +1,15 @@ #!/usr/bin/env bash +has() { + type "$1" &>/dev/null +} + +if has doc::maybe_help; then + return 0 +fi + +# echo "IMPORTED MAIN: $0" >&2 + if ${DOT_DEBUG:-false}; then set -x fi @@ -30,6 +40,7 @@ log::ansi() { fi local -r txt="$*" case "${mod1}${mod2}" in + "--bold") printf "\033[1m%s\033[0m" "$txt" ;; "--blue") printf "\033[34m%s\033[39m" "$txt" ;; "--blue--inverse") printf "\033[34m\033[7m%s\033[27;39m" "$txt" ;; "--magenta") printf "\033[35m%s\033[39m" "$txt" ;; @@ -73,19 +84,38 @@ debug() { "$@" } -has() { - type "$1" &>/dev/null -} - export_f() { export -f "${@?}" >/dev/null } -export_f has tap println echoerr +yaml::export() { + if ${DOT_YAML_PARSED:-false}; then + return 0 + fi -if has doc::parse; then - return 0 -fi + eval "$(dot script yaml "${DOTFILES}/config.yaml" "DOT_")" + + local -r override="${DOTFILES}/local/config.yaml" + if [ -f "$override" ]; then + eval "$(dot script yaml "$override" "DOT_")" + fi + + export DOT_YAML_PARSED=true +} + +yaml::var() { + local -r varname="DOT_${1:-}" + + yaml::export + + if [ -z "${!varname:-}" ]; then + local -r default="${2:-false}" + echo "$default" + return 0 + fi + + echo "${!varname}" +} export PATH="${DOTFILES}/bin/:${PATH}:/usr/local/bin:/usr/bin:${HOME}/bin" @@ -94,7 +124,7 @@ if ${DOT_TRACE:-false}; then set -x fi -export EDITOR="${EDITOR:-vi}" +export EDITOR="${EDITOR:-v}" if ! has sudo; then sudo() { "$@"; } @@ -126,34 +156,30 @@ if has ggrep; then export_f sed awk find head mktemp date cut tr cp cat sort kill xargs fi -doc::help_msg() { +doc::_help_msg() { local -r sh_file="$1" grep "^##?" "$sh_file" | cut -c 5- } doc::maybe_help() { local -r sh_file="$0" + + local show_if_no_args=false + if [ "${1:-}" = "--show-if-no-args" ]; then + shift || true + show_if_no_args=true + fi doc::autocomplete "$@" - case "${1:-}" in - -h|--help|--version) doc::help_msg "$sh_file"; exit 0 ;; - esac -} - -doc::help_or_fail() { - local -r sh_file="$0" - - doc::autocomplete "$@" + if $show_if_no_args && [ $# = 0 ]; then + doc::_help_msg "$sh_file" + exit 0 + fi case "${1:-}" in - -h|--help|--version) doc::help_msg "$sh_file"; exit 0 ;; + -h|--help|--version) doc::_help_msg "$sh_file"; exit 0 ;; esac - - echoerr "Invalid command" - echoerr - doc::help_msg "$sh_file" - exit 1 } doc::parse() { @@ -161,7 +187,7 @@ doc::parse() { doc::autocomplete "$@" - local -r help="$(doc::help_msg "$sh_file")" + local -r help="$(doc::_help_msg "$sh_file")" local docopt="${DOT_DOCOPT:-}" if [ -z "${docopt:-}" ]; then @@ -205,5 +231,3 @@ doc::autocomplete() { exit 1 fi } - -export_f doc::help_msg doc::maybe_help doc::help_or_fail doc::parse doc::autocomplete diff --git a/scripts/core/platform.sh b/scripts/core/platform.sh index dced9f57..0e0e8030 100644 --- a/scripts/core/platform.sh +++ b/scripts/core/platform.sh @@ -77,10 +77,13 @@ platform::main_package_manager() { platform::existing_command() { local cmd for cmd in "$@"; do + # echoerr "cmd: $cmd" if has "$cmd"; then + # echoerr "has $cmd" echo "$cmd" return 0 fi + # echoerr "doesn't have $cmd" done return 1 } diff --git a/scripts/core/str.sh b/scripts/core/str.sh index c60ffc14..3e1f5f23 100644 --- a/scripts/core/str.sh +++ b/scripts/core/str.sh @@ -100,6 +100,7 @@ str::remove_last_char() { } str::urlencode() { + set +e local data data="$(curl -s -o /dev/null -w '%{url_effective}' --get --data-urlencode "$1" "")" if [[ $? != 3 ]]; then diff --git a/scripts/core/test.sh b/scripts/core/test.sh index a601e4b4..b96c0e9b 100644 --- a/scripts/core/test.sh +++ b/scripts/core/test.sh @@ -121,6 +121,7 @@ test::start() { for test in $(test::find_files "$@"); do seconds=$SECONDS RAN=false + log::debug "Start running tests in ${test}..." # shellcheck disable=SC1090 source "$test" if ! $RAN; then diff --git a/scripts/filesystem/jump b/scripts/filesystem/jump index 2c414153..b0dbde66 100755 --- a/scripts/filesystem/jump +++ b/scripts/filesystem/jump @@ -120,7 +120,7 @@ jump_to_specific_folder() { jump_to_work_folder() { cd "$DEV_HOME" - local -r GO_DIR="${DEV_HOME}/go/src/code.uber.internal" + local -r GO_DIR="${DEV_HOME}/go/src/code.uber.internal" # TODO _go_projs() { cd "$GO_DIR" @@ -133,7 +133,7 @@ jump_to_work_folder() { } _suffix() { - awk -v suffix="$1" -v color="$2" '{printf("%s%sm%-32s%s\n", NC "\033[0;", color, $1, suffix) }' + awk -v suffix="$1" -v color="$2" '{printf("%s%sm%-46s%s\n", NC "\033[0;", color, $1, suffix) }' } _cd() { diff --git a/scripts/filesystem/remove-empty-dirs b/scripts/filesystem/remove-empty-dirs index 18a0d4d2..cd3c94fc 100755 --- a/scripts/filesystem/remove-empty-dirs +++ b/scripts/filesystem/remove-empty-dirs @@ -13,7 +13,9 @@ doc::maybe_help "$@" main() { local -r path="$1" - for _ in $(seq 0 10); do + find "$path" -name '.DS_Store' -type f -delete || true + + for _ in $(seq 0 5); do find "$path" -type d -exec rmdir {} + 2>/dev/null done } diff --git a/scripts/gaming/cemu b/scripts/game/cemu similarity index 91% rename from scripts/gaming/cemu rename to scripts/game/cemu index 5a548a81..ff8e08b4 100755 --- a/scripts/gaming/cemu +++ b/scripts/game/cemu @@ -10,7 +10,7 @@ source "${DOTFILES}/scripts/core/main.sh" doc::maybe_help "$@" -CEMU_DIR="${CEMU_DIR:-/mnt/d/Emulators/Cemu}" +CEMU_DIR="$(yaml::var game_cemu_dir)" SAVE_BASE="${CEMU_DIR}/mlc01/usr/" _gen_list() { diff --git a/scripts/gaming/igdb b/scripts/game/igdb similarity index 100% rename from scripts/gaming/igdb rename to scripts/game/igdb diff --git a/scripts/gaming/images b/scripts/game/images similarity index 100% rename from scripts/gaming/images rename to scripts/game/images diff --git a/scripts/game/launch b/scripts/game/launch new file mode 100755 index 00000000..507e877b --- /dev/null +++ b/scripts/game/launch @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/core/main.sh" + +##? Launch game +##? +##? Usage: +##? launch <system> <path> + +doc::maybe_help "$@" + +main() { + # local -r system="$1" + # local -r path="$2" + + # dot channel notify "$path" "$system" + # open "https://google.com?q=${system}" + log::warn "TODO" +} + +main "$@" \ No newline at end of file diff --git a/scripts/game/louvre b/scripts/game/louvre new file mode 100755 index 00000000..740c434e --- /dev/null +++ b/scripts/game/louvre @@ -0,0 +1,114 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/core/main.sh" + +##? Helpers for louvre +##? +##? Usage: +##? louvre config + +doc::maybe_help "$@" + +libretro() { + local -r core="$1" + echo 'am start -n com.retroarch.aarch64/com.retroarch.browser.retroactivity.RetroActivityFuture -e ROM "{file.path}" -e LIBRETRO /data/data/com.retroarch.aarch64/cores/'"$core"'_libretro_android.so -e CONFIGFILE /storage/emulated/0/Android/data/com.retroarch.aarch64/files/retroarch.cfg -e QUITFOCUS --activity-clear-task --activity-clear-top --activity-no-history' +} + +citra_mmj() { + echo 'am start -n org.citra.emu/.ui.MainActivity -a android.intent.action.VIEW -e GamePath "{file.path}" --activity-clear-task --activity-clear-top --activity-no-history' +} + +aether() { + echo 'am start -n xyz.aethersx2.android/.EmulationActivity -a android.intent.action.MAIN -e bootPath "{file.documenturi}" --activity-clear-task --activity-clear-top --activity-no-history' +} + +skyline() { + echo 'am start -n skyline.emu/emu.skyline.EmulationActivity -a android.intent.action.VIEW -d "{file.path}"' +} + +dolphin() { + echo 'am start -n org.dolphinemu.dolphinemu/.ui.main.MainActivity -a android.intent.action.VIEW --activity-clear-task --activity-clear-top --activity-no-history' # -e AutoStartFile "{file.path}" +} + +# drastic() { +# echo 'am start -n com.dsemu.drastic/.DraSticActivity -a android.intent.action.VIEW -d "{file.path}" --activity-clear-task --activity-clear-top --activity-no-history' +# } + +collection() { + local -r platform="$1" + local -r name="$2" + local -r launch="$3" + local -r extensions="$(echo "$4" | tr ',' '\n' | sed 's/^/ - /')" + + cat << EOF + - name: ${name} + path: ${ROMS}/${platform} + extensions: +${extensions} + platform: ${platform} + denylist: ~ + launch: $launch +EOF +} + +gen_collections() { + collection gbc "Game Boy Color" "$(libretro gambatte)" "zip,rar,7z,dmg,gb,gbc" + collection gba "Game Boy Advance" "$(libretro mgba)" "zip,rar,7z,gb,gba,gbc" + collection nds "Nintendo DS" "$(libretro melonds)" "zip,rar,7z,bin,dsi,nds" + collection 3ds "Nintendo 3DS" "$(citra_mmj)" "zip,rar,7z,3ds,cia,3dsx,app,axf,cci,cxi,elf" + collection nes "Nintendo Entertainment System" "$(libretro bnes)" "zip,rar,7z,nes" + collection snes "Super Nintendo" "$(libretro snes9x)" "zip,rar,7z,bs,fig,sfc,smc,st,swc" + collection psp "PSP" "$(libretro ppsspp)" "zip,rar,7z,cso,elf,iso,pbp,prx" + collection n64 "Nintendo 64" "$(libretro mupen64plus_next)" "zip,rar,7z,bin,n64,u1,v64,z64" + collection ps1 "Playstation" "$(libretro duckstation)" "bin,cue" + collection ps2 "Playstation 2" "$(aether)" "bin,chd,ciso,cso,cue,dump,elf,gz,img,iso,isz,m3u,mdf,nrg" + collection ps3 "Playstation 3" "$(libretro rpcs3)" "bin" + collection gc "Nintendo GameCube" "$(dolphin)" "ciso,dff,dol,elf,gcm,gcz,iso,m3u,rvz,tgc,wad,wbfs" + collection wii "Nintendo Wii" "$(dolphin)" "ciso,dff,dol,elf,gcm,gcz,iso,m3u,rvz,tgc,wad,wbfs" + collection switch "Nintendo Switch" "$(skyline)" "iso,cia,nsp,nsz" + # collection cps2 "CPS2" "$(libretro fbalpha2012_cps2)" "zip,rar,7z,fba" +} + +gen_yaml() { + export ROMS="${ROMS:-$(get_roms_dir)}" + + local -r collections="$(gen_collections)" + local -r client_id="$(dot sec store get louvre/client_id)" + local -r client_secret="$(dot sec store get louvre/client_secret)" + + cat << EOF +parallelism: + workers: 4 +igdb: + api_base_url: "https://api.igdb.com" + images_base_url: "https://images.igdb.com" +twitch: + client_id: ${client_id} + client_secret: ${client_secret} + id_base_url: "https://id.twitch.tv" +collections: +${collections} +tracing: + time: false + level: louvre=info +EOF +} + +main() { + gen_yaml +} + +get_roms_dir() { + for f in "/sdcard/ROMS" "/storage/7FAF-1201/ROMs" "${HOME}/ROMs"; do + if [ -d "$f" ]; then + echo "$f" + return + fi + done + + exit 1 +} + + +main "$@" diff --git a/scripts/gaming/ps4 b/scripts/game/ps4 similarity index 100% rename from scripts/gaming/ps4 rename to scripts/game/ps4 diff --git a/scripts/gaming/rom b/scripts/game/rom similarity index 100% rename from scripts/gaming/rom rename to scripts/game/rom diff --git a/scripts/gaming/playnite b/scripts/gaming/playnite deleted file mode 100755 index b460d216..00000000 --- a/scripts/gaming/playnite +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -source "${DOTFILES}/scripts/core/main.sh" - -##? Playnite helpers -##? -##? Usage: -##? playnite games -##? playnite set - -doc::parse "$@" - -LIBRARY_DIR="${HOME}/Downloads/library" - -if $games; then - cat "$LIBRARY_DIR"/games/* | jq -r '.Name' -elif $set; then - game="$(cat "$LIBRARY_DIR"/games/* \ - | jq -r '.Name' \ - | fzf --height '50%')" - dot gaming images "$game" -fi diff --git a/scripts/git/changelog b/scripts/git/changelog deleted file mode 100755 index e7a26242..00000000 --- a/scripts/git/changelog +++ /dev/null @@ -1,195 +0,0 @@ -#!/usr/bin/env bash - -source "${DOTFILES}/scripts/git/aux/core.sh" -source "${DOTFILES}/scripts/core/str.sh" - -##? Changelog generator -##? -##? Usage: -##? changelog release (github|local) -##? changelog commit - -doc::parse "$@" - -main() { - IFS=$'\n' - if $local; then - git::changelog_release_local "$@" - elif $github; then - git::changelog_release_github "$@" - elif $commit; then - git::changelog_commit "$@" - fi -} - -github::lines() { - local -r reg='commit\/([^">]+).*>(.+?) \(<\/.*?pull\/([0-9]+)' - # TODO: pbpaste - pbpaste | grep -Eo "$reg" | sed -E "s/${reg}/\1;\2\;\3/" -} - -github::process_line() { - local -r line="$1" - local commit - commit="$(echo "$line" | cut -d';' -f1)" - commit="${commit:0:5}" - local -r name="$(echo "$line" | cut -d';' -f2)" - local -r pr="$(echo "$line" | cut -d';' -f3)" - - local extra="" - if [ -n "$pr" ]; then - extra=" ([#${pr}](${REPO_URL}/issues/${pr}))" - fi - - echo "- [\`${commit}\`](${REPO_URL}/commit/${commit}) ${name}${extra}" -} - -github::changelog() { - echoerr "BROKEN" - echoerr "Copy output from ${REPO_URL}/compare/${tag_older}...${tag_newer} into the clipboard" - - pbpaste - - # local tag_older="$1" - # local tag_newer="$2" - # curl -s "${REPO_URL}/compare/${tag_older}...${tag_newer}" -} - -git::changelog_release_github() { - echo "### :sparkles: New features -### :bug: Fixes -### :computer: Code quality -### :information_source: Context -### :bangbang: Breaking changes" - echo - echo - - REPO_URL="$(_repo_url)" - - pairs=() - while IFS='' read -r line; do pairs+=("$line"); done < <(_all_tags) - - len="${#pairs[@]}" - - for i in $(seq 0 $((len - 2))); do - tag_older="${pairs[$((len - i - 2))]}" - tag_newer="${pairs[$((len - i - 1))]}" - echo "[${tag_newer}]" - for l in $(github::changelog "$tag_older" "$tag_newer" | github::lines); do - github::process_line "$l" - done - echo - echo - exit 1 # TODO - done -} - -git::changelog_commit() { - cd "$(git::root)" || exit - - local -r changes="$(git diff --numstat HEAD \ - | awk '{print $3" "$1-$2}' \ - | sort -k2 -n -r \ - | awk '{print $1}' \ - | sed -E 's|(.*)/(.*)|\2|g')" - - local -r n="$(printf '%s' "$changes" \ - | wc -l \ - | xargs)" - - - local msg - msg="$(printf '%s' "$changes" \ - | head -n3 \ - | tr '\n' ';' \ - | sed -E 's/ *; */, /g' \ - | sed -E 's/ *, *$//g')" - - [[ $n -gt 3 ]] && msg="${msg}, ..." - - echo "$(date +'%b-%d %Hh%M'): ${msg}" -} - -git::changelog_release_local() { - REPO_URL="$(_repo_url)" - - pairs=() - while IFS='' read -r line; do pairs+=("$line"); done < <(_all_tags) - - len="${#pairs[@]}" - - for i in $(seq 0 $((len - 2))); do - tag_older="${pairs[$((len - i - 2))]}" - tag_newer="${pairs[$((len - i - 1))]}" - _commits "$tag_older" "$tag_newer" - echo - echo - done -} - -_repo_url() { - cat "$(git::root)/.git/config" \ - | grep origin -A1 \ - | grep url \ - | awk '{print $NF}' \ - | head -n1 \ - | tr ':' '/' \ - | sed 's|git@|https://|g' \ - | sed -E 's/.git$//' -} - -_remove_empty_lines() { - sed -E '/^\s*$/d' -} - -_capture() { - perl -pe 's/([a-z\d]+)\s+(.*)/\1;\2/s' -} - -_format() { - while IFS= read -r line; do - local -r commit="$(echo "$line" | cut -d';' -f1 | xargs | cut -c1-5)" - local -r msg="$(echo "$line" | cut -d';' -f2 | sed -E "s|\(#([0-9]+)\)|([#\1](${REPO_URL}/issues/\1))|g")" - echo "- [\`${commit}\`](${REPO_URL}/commit/${commit}) ${msg}" - done -} - -_dedupe() { - awk '!visited[$0]++' -} - -_cleanup() { - grep -v 'Author:' \ - | grep -v 'Date:' \ - | grep -v 'Merge pull request' \ - | grep -v 'Merge:' \ - | _remove_empty_lines \ - | grep '^commit ' -A1 \ - | sed -E 's/commit\s+([a-f0-9]+)/\1/g' \ - | sed 'N;s/\n/ /' \ - | perl -pe 's/^--\s([a-f0-9]+)\s+/\1/g' \ - | grep -v '^--' \ - | grep -v '\-\-$' \ - | _capture \ - | _dedupe \ - | _format -} - -_commits() { - local -r tag_older="$1" - local -r tag_newer="$2" - - local -r tag_date="$(git log -1 --format=%ai v2.3.1 | awk '{print $1}')" - - echo "## [${tag_newer}](${REPO_URL}/releases/tag/${tag_newer}) - ${tag_date}" - - git log "${tag_older}..${tag_newer}" --grep '#' \ - | _cleanup -} - -_all_tags() { - git for-each-ref --sort=creatordate --format '%(refname)' refs/tags \ - | sed 's|refs/tags/||g' -} - -main "$@" diff --git a/scripts/git/commit b/scripts/git/commit index 60d4e03b..0462eb95 100755 --- a/scripts/git/commit +++ b/scripts/git/commit @@ -7,11 +7,37 @@ source "${DOTFILES}/scripts/git/aux/core.sh" ##? Usage: ##? commit am <args>... +git::changelog_commit() { + cd "$(git::root)" || exit + + local -r changes="$(git diff --numstat HEAD \ + | awk '{print $3" "$1-$2}' \ + | sort -k2 -n -r \ + | awk '{print $1}' \ + | sed -E 's|(.*)/(.*)|\2|g')" + + local -r n="$(printf '%s' "$changes" \ + | wc -l \ + | xargs)" + + + local msg + msg="$(printf '%s' "$changes" \ + | head -n3 \ + | tr '\n' ';' \ + | sed -E 's/ *; */, /g' \ + | sed -E 's/ *, *$//g')" + + [[ $n -gt 3 ]] && msg="${msg}, ..." + + echo "$(date +'%b-%d %Hh%M'): ${msg}" +} + _msg() { if [[ $# -gt 0 ]] && [[ "${1:-}" != "wip" ]]; then echo "$*" else - dot git changelog commit + git::changelog_commit "$@" fi } @@ -25,5 +51,5 @@ _am() { cmd="${1:-}" case $cmd in am) _am "$@" ;; - *) doc::help_or_fail "$@" ;; + *) log::error "Invalid command: $*" ;; esac diff --git a/scripts/git/push b/scripts/git/push index 4861265b..64d2ce50 100755 --- a/scripts/git/push +++ b/scripts/git/push @@ -19,7 +19,7 @@ _should_use_arc() { _upstream() { local -r branch="$(git rev-parse --abbrev-ref HEAD)" if _should_use_arc; then - arc diff --message "$(git log -1 --pretty=%B)" --nounit + arc diff --message "$(git log -1 --pretty=%B)" --nounit --nolint --excuse=ci else git push -u origin "$branch" fi diff --git a/scripts/notification/bar b/scripts/notification/bar deleted file mode 100755 index 7a0eb2dd..00000000 --- a/scripts/notification/bar +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -source "${DOTFILES}/scripts/core/main.sh" - -##? Alerts using WM's bar -##? -##? Usage: -##? bar <msg> - -doc::maybe_help "$@" - -# how long should the popup remain? -duration=3 - -# define geometry -barw=300 -barh=35 -barx=$(xdpyinfo | grep dimensions | tr -s ' ' ';' | cut -f 3 -d ';' | cut -f 1 -d 'x') -bary=$(xdpyinfo | grep dimensions | tr -s ' ' ';' | cut -f 3 -d ';' | cut -f 2 -d 'x') -barx=$((barx/2 - barw/2)) -bary=$((bary/2 - barh/2)) - -# colors -bar_bg='#64000000' -bar_fg='#ffffffff' - -# font used -bar_font_1='System San Francisco Display-16' -bar_font_2='FontAwesome-16' - -# computation -baropt="-d -g ${barw}x${barh}+${barx}+${bary} -f ${bar_font_1} -f ${bar_font_2} -F${bar_fg} -B${bar_bg}" - -# create the popup and make it live for 3 seconds -( - echo -e "${1}" - sleep ${duration} -) | lemonbar "${baropt}" diff --git a/scripts/notification/push b/scripts/notification/push deleted file mode 100755 index 5d194085..00000000 --- a/scripts/notification/push +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -source "${DOTFILES}/scripts/core/main.sh" - -##? Pushbullet API -##? -##? Usage: -##? push [options] list -##? push [options] note <title> [<message>] -##? push [options] url <uri> -##? push [options] url <title> [<message>] <uri> -##? push [options] auth -##? push [options] app <name> -##? push [options] shot -##? push [options] write <text> -##? push [options] say <text> -##? push [options] share <text> -##? push [options] raw <args>... -##? -##? Options: -##? -d --device <device> Device to push [default: phone] -##? -##? Examples: -##? push list -##? push note sometext -##? push url http://google.com -##? push app Gmail --device tablet - -doc::parse "$@" - -PUSHBULLET_HOME="${PUSHBULLET_HOME:-${DOTFILES}/modules/pushbullet-bash}" - -if [ -z "${PUSHBULLET_API_KEY:-}" ]; then - die "Please set \$PUSHBULLET_API_KEY first" -fi - -best_match() { - "$0" list \ - | fzf --filter="$*" \ - | head -n1 -} - -build_msg() { - local -r type="$1" - local -r txt="${2:-null}" - echo "${type};${txt}" -} - -call_api() { - cd "$PUSHBULLET_HOME" - PB_API_KEY="$PUSHBULLET_API_KEY" bash ./pushbullet "${@:-}" -} - -# call cli with raw args -if [[ ${#args[@]} -gt 0 ]]; then - call_api "${args[@]:-}" - exit 0 -fi - -if ! $list && [ -n "${device:-}" ]; then - case "$device" in - moto|g4) device="Moto G4 Plus" ;; - phone|xiaomi|mi|9t|pro) device="Xiaomi Mi 9T Pro" ;; - tablet|tab|galaxy|samsung) device="Galaxy Tab A" ;; - all|broadcast) device="all" ;; - chrome|pc|desktop|mac|windows|computer|win|osx|linux|notebook) device="Chrome" ;; - *) device="$(best_match "$device")" ;; - esac -fi - -if $list; then - args=("list") -elif $url; then - args=("push" "$device" "link") - [ -n "${title:-}" ] && args+=("$title") - [ -n "${message:-}" ] && args+=("$message") - [ -n "${uri:-}" ] && args+=("$uri") -else - args=("push" "$device" "note") - if $note; then - [ -n "${title:-}" ] && args+=("$title") - [ -n "${message:-}" ] && args+=("$message") - elif $app; then - args+=("$(build_msg app "$name")") - elif $shot; then - args+=("$(build_msg shot)") - elif $auth; then - args+=("$(build_msg auth)") - elif $write; then - args+=("$(build_msg write "$text")") - elif $say; then - args+=("$(build_msg say "$text")") - elif $share; then - args+=("$(build_msg share "$text")") - fi -fi - -# clone repository if needed -dot pkg add pushbullet-bash &> /dev/null - -# call cli -if ! $list; then - log::warn "${args[@]:-}" -fi -call_api "${args[@]:-}" diff --git a/scripts/package/add b/scripts/package/add index e727b792..2e0f910c 100755 --- a/scripts/package/add +++ b/scripts/package/add @@ -24,13 +24,13 @@ if [[ "$1" == "--prevent-recipe" ]]; then shift fi -if [ $# -gt 1 ]; then - pkg_failures=0 - for package in "$@"; do - dot pkg add "$($prevent_recipe && printf %s '--prevent-recipe')" "$package" || pkg_failures=$((pkg_failures+1)) - done - exit "$pkg_failures" -fi +# if [ $# -gt 1 ]; then +# pkg_failures=0 +# for package in "$@"; do +# dot pkg add "$($prevent_recipe && printf %s '--prevent-recipe')" "$package" || pkg_failures=$((pkg_failures+1)) +# done +# exit "$pkg_failures" +# fi _log::installing() { local suffix="" diff --git a/scripts/package/aux/dependencies.ini b/scripts/package/aux/dependencies.ini index 878a3d8b..fc091dd6 100644 --- a/scripts/package/aux/dependencies.ini +++ b/scripts/package/aux/dependencies.ini @@ -2,26 +2,29 @@ curl git bash +vi [mini] fzf wget +vim nvim unzip jq navi exa -gron docpars +fre +zsh [dev] +gron rg tree nnn spacevim zsh tmux -fre gitui bat ag diff --git a/scripts/package/aux/recipe.sh b/scripts/package/aux/recipe.sh index 44468929..223275ed 100644 --- a/scripts/package/aux/recipe.sh +++ b/scripts/package/aux/recipe.sh @@ -3,7 +3,6 @@ source "${DOTFILES}/scripts/core/fs.sh" TMP_DIR="$(platform::get_tmp_dir)" -MODULES_FOLDER="${DOTFILES}/modules" recipe::folder() { echo "${TMP_DIR}/${1}" @@ -43,26 +42,20 @@ recipe::shallow_gitlab_clone() { recipe::shallow_git_clone "$@" } +recipe::check_if_can_build() { + if ! ${DOT_PKG_ALLOW_BUILD:-true}; then + log::error "Building binaries not allowed!" + exit 1 + fi +} + recipe::make() { + recipe::check_if_can_build local -r repo="$1" cd "$(recipe::folder "$repo")" || exit make && sudo make install } -recipe::has_submodule() { - local -r module="$1" - local -r probe_file="${2:-}" - - local -r module_path="${MODULES_FOLDER}/${module}" - - if [[ -n $probe_file ]]; then - local -r probe_path="${module_path}/${probe_file}" - fs::is_file "$probe_path" - else - fs::is_dir "$module_path" - fi -} - recipe::clone_as_submodule() { local -r user="$1" local -r repo="$2" @@ -79,6 +72,8 @@ recipe::clone_as_submodule() { } recipe::install_from_git() { + recipe::check_if_can_build + local -r repo="$(echo "$@" | tr ' ' '/')" local -r package="$(basename "$repo")" @@ -99,12 +94,10 @@ recipe::cargo() { local -r cargo_name="$1" local -r pkg_manager_name="${2:-$cargo_name}" - if has cargo; then - cargo install "$cargo_name" + if dot pkg add --prevent-recipe "$pkg_manager_name"; then + return 0 else - if dot pkg add --prevent-recipe "$pkg_manager_name"; then - return 0 - fi + recipe::check_if_can_build dot pkg add cargo cargo install "$cargo_name" fi diff --git a/scripts/package/batch b/scripts/package/batch index ddc22b77..6dfe7a17 100755 --- a/scripts/package/batch +++ b/scripts/package/batch @@ -64,14 +64,6 @@ case "$name" in ;; esac -packages=() -while IFS='' read -r line; do packages+=("$line"); done < <(_list) - -if dot pkg check "${packages[@]}" &> /dev/null; then - log::info "All dependencies already installed for the batch $name" - exit 0 -fi - if $prompt; then log::warn "There are missing dependencies for the batch $name" if ! feedback::confirmation "Do you want to install it?"; then @@ -80,7 +72,9 @@ if $prompt; then fi if $add; then - deps=() - while IFS='' read -r line; do deps+=("$line"); done < <(batch::dependencies "$name") - dot pkg add "${deps[@]}" + echoerr add + IFS=$'\n' + for dep in $(batch::dependencies "$name"); do + dot pkg add "$dep" || true + done fi diff --git a/scripts/package/check b/scripts/package/check index d0327f8a..d9d96b33 100755 --- a/scripts/package/check +++ b/scripts/package/check @@ -20,13 +20,13 @@ else prevent_recipe=false fi -if [ $# -gt 1 ]; then - pkg_failures=0 - for package in "$@"; do - dot pkg check "$($prevent_recipe && printf %s '--prevent-recipe')" "$package" || pkg_failures=$((pkg_failures+1)) - done - exit "$pkg_failures" -fi +# if [ $# -gt 1 ]; then +# pkg_failures=0 +# for package in "$@"; do +# dot pkg check "$($prevent_recipe && printf %s '--prevent-recipe')" "$package" || pkg_failures=$((pkg_failures+1)) +# done +# exit "$pkg_failures" +# fi exit::is_installed() { log::success "${package} is installed" diff --git a/scripts/package/pkg_managers/apt.sh b/scripts/package/pkg_managers/apt.sh index 2d73f9ec..e7e8a766 100644 --- a/scripts/package/pkg_managers/apt.sh +++ b/scripts/package/pkg_managers/apt.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash _apt() { - sudo apt-get "$@" + apt-get "$@" } apt::install() { diff --git a/scripts/package/pkg_managers/pacman.sh b/scripts/package/pkg_managers/pacman.sh index d1697877..6906deab 100644 --- a/scripts/package/pkg_managers/pacman.sh +++ b/scripts/package/pkg_managers/pacman.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash _pacman() { - sudo pacman --color=always "$@" + pacman --color=always "$@" } pacman::install() { diff --git a/scripts/package/pkg_managers/yum.sh b/scripts/package/pkg_managers/yum.sh index 54938c91..f1e4ab0f 100644 --- a/scripts/package/pkg_managers/yum.sh +++ b/scripts/package/pkg_managers/yum.sh @@ -1,33 +1,33 @@ #!/usr/bin/env bash yum::install() { - sudo yum install "$@" + yum install "$@" } yum::remove() { - sudo yum uninstall "$@" + yum uninstall "$@" } yum::update() { - sudo yum updateinfo "$@" + yum updateinfo "$@" } yum::upgrade() { - sudo yum update "$@" + yum update "$@" } yum::clean() { - sudo yum clean "$@" + yum clean "$@" } yum::search() { - sudo yum search "$@" + yum search "$@" } yum::list() { - sudo yum list "$@" + yum list "$@" } yum::info() { - sudo yum info "$@" + yum info "$@" } diff --git a/scripts/package/proxy b/scripts/package/proxy index e4655362..12afb1ee 100755 --- a/scripts/package/proxy +++ b/scripts/package/proxy @@ -57,4 +57,12 @@ file="${DOTFILES}/scripts/package/pkg_managers/${pkg_manager}.sh" source "$file" fn="${pkg_manager}::$(_actual_operation "$operation")" -"$fn" "$@" + +yaml::export +use_sudo="$(yaml::var "pkg_sudo_${pkg_manager}" false)" + +if $use_sudo; then + sudo "$fn" "$@" +else + "$fn" "$@" +fi diff --git a/scripts/package/recipes/docpars.sh b/scripts/package/recipes/docpars.sh index 18704e6e..1d1175a9 100644 --- a/scripts/package/recipes/docpars.sh +++ b/scripts/package/recipes/docpars.sh @@ -2,6 +2,9 @@ set -euo pipefail package::install() { - if has brew && brew install denisidoro/tools/docpars; then return 0; fi + if has brew && brew install denisidoro/tools/docpars; then + return 0 + fi + recipe::cargo docpars } diff --git a/scripts/package/recipes/dot-folders.sh b/scripts/package/recipes/dot-folders.sh index 848faa2f..d21faf12 100644 --- a/scripts/package/recipes/dot-folders.sh +++ b/scripts/package/recipes/dot-folders.sh @@ -10,9 +10,8 @@ _mkdir() { } package::install() { - _mkdir "${DOTFILES}/local" - _mkdir "${DOTFILES}/local/tmp" - _mkdir "${DOTFILES}/local/bin" + _mkdir "${DOTFILES}/local/${DOT_INSTANCE}/tmp" + _mkdir "${DOTFILES}/local/${DOT_INSTANCE}/bin" _mkdir "${DOTFILES}/target" _mkdir "${DOTFILES}/bin" diff --git a/scripts/package/recipes/dot-git.sh b/scripts/package/recipes/dot-git.sh deleted file mode 100644 index 5cf1f32a..00000000 --- a/scripts/package/recipes/dot-git.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -DEFAULT_DOTFILES="${HOME}/dotfiles" - -package::is_installed() { - return 1 -} - -_default_available() { - [[ -f "${DEFAULT_DOTFILES}/bin/dot" ]] -} - -_symlink() { - if [ -d "$DEFAULT_DOTFILES" ]; then - log::warn "Backing up existing dotfiles folder and symlinking new dotfiles..." - old_dotfiles=$(mktemp -u -d "${DOTFILES}_XXXX") - mv "$DEFAULT_DOTFILES" "$old_dotfiles" - fi - - ln -s "$DOTFILES" "$DEFAULT_DOTFILES" -} - -package::install() { - dot pkg add git - - cd "$DOTFILES" - - git submodule init || true - git submodule update || true - git submodule foreach git reset --hard || true - git submodule foreach git checkout . || true - git submodule foreach git pull origin master || true - - if ! _default_available; then - _symlink - fi -} diff --git a/scripts/package/recipes/dot-zshrc.sh b/scripts/package/recipes/dot-local-zshrc.sh similarity index 73% rename from scripts/package/recipes/dot-zshrc.sh rename to scripts/package/recipes/dot-local-zshrc.sh index e9640be2..1aeaf3ec 100644 --- a/scripts/package/recipes/dot-zshrc.sh +++ b/scripts/package/recipes/dot-local-zshrc.sh @@ -1,20 +1,16 @@ #!/usr/bin/env bash set -euo pipefail -ZSHRC_PATH="${DOTFILES}/local/zshrc" +ZSHRC_PATH="${DOTFILES}/local/${DOT_INSTANCE}/zshrc" package::is_installed() { - return 1 + [ -f "$ZSHRC_PATH" ] } _content() { echo "#!/usr/bin/env bash" echo echo "export DOT_DOCOPT=\"${DOT_DOCOPT:-python}\"" - echo "export DOT_FRE=${DOT_FRE:-true}" - echo "export DOT_FZF=${DOT_FZF:-true}" - echo "export DOT_NAVI=${DOT_NAVI:-true}" - echo "export DOT_ZIM=${DOT_ZIM:-true}" echo "export DOT_THEME=${DOT_THEME:-powerlevel}" if [ -n "${DOT_ZSHRC_EXTRA:-}" ]; then echo @@ -23,7 +19,7 @@ _content() { } package::install() { - dot pkg add dot-folders + dot pkg add dot-folders || true if ! [ -f "$ZSHRC_PATH" ]; then dot pkg add "$EDITOR" || true @@ -51,7 +47,7 @@ package::install() { dot pkg add fzf || true fi - if ${DOT_ZIM:-false}; then - dot pkg add zim - fi + if [ "${DOT_THEME:-}" == "powerlevel" ]; then + dot pkg add zim-modules || true + fi } diff --git a/scripts/package/recipes/dot-source-shellrc.sh b/scripts/package/recipes/dot-source-shellrc.sh new file mode 100644 index 00000000..1d090e57 --- /dev/null +++ b/scripts/package/recipes/dot-source-shellrc.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -euo pipefail + +_gen_file() { + local -r shell="$1" + echo "${HOME}/.${shell}rc" +} + +package::is_installed() { + local -r f="$(_gen_file bash)" + + if ! [ -f "$f" ]; then + return 1 + fi + + cat "$f" | grep -q 'DOTFILES' +} + +_install() { + local -r shell="$1" + local -r f="$(_gen_file "$shell")" + + if ! [ -f "$f" ]; then + touch "$f" + fi + + echo "source '${DOTFILES}/shell/${shell}/${shell}rc'" >> "$f" +} + +package::install() { + _install bash + _install zsh +} diff --git a/scripts/package/recipes/fzf-latest.sh b/scripts/package/recipes/fzf-latest.sh new file mode 100644 index 00000000..6c30d166 --- /dev/null +++ b/scripts/package/recipes/fzf-latest.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail + +package::install() { + recipe::shallow_github_clone junegunn fzf # TODO + cd "$TMP_DIR/fzf" + yes | ./install +} diff --git a/scripts/package/recipes/fzf.sh b/scripts/package/recipes/fzf.sh index 1c8e78de..145cb2a7 100644 --- a/scripts/package/recipes/fzf.sh +++ b/scripts/package/recipes/fzf.sh @@ -2,11 +2,13 @@ set -euo pipefail package::install() { - if dot pkg add --prevent-recipe fzf; then return 0; fi + if dot pkg add --prevent-recipe fzf; then + return 0 + fi + recipe::check_if_can_build dot pkg add git recipe::shallow_github_clone junegunn fzf # TODO cd "$TMP_DIR/fzf" - yes | ./install } diff --git a/scripts/package/recipes/navi.sh b/scripts/package/recipes/navi.sh index 67d384ff..5acfb634 100644 --- a/scripts/package/recipes/navi.sh +++ b/scripts/package/recipes/navi.sh @@ -2,8 +2,11 @@ set -euo pipefail package::install() { - if recipe::cargo navi; then return 0; fi + if recipe::cargo navi; then + return 0; + fi + recipe::check_if_can_build dot pkg add curl bash <(curl -sL https://raw.githubusercontent.com/denisidoro/navi/master/scripts/install) } diff --git a/scripts/package/recipes/pushbullet-bash.sh b/scripts/package/recipes/pushbullet-bash.sh deleted file mode 100644 index 331ed780..00000000 --- a/scripts/package/recipes/pushbullet-bash.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -user="Red5d" -repo="pushbullet-bash" - -package::is_installed() { - recipe::has_submodule $repo "pushbullet" -} - -package::install() { - dot pkg add git - - recipe::clone_as_submodule $user $repo -} \ No newline at end of file diff --git a/scripts/package/recipes/spacevim.sh b/scripts/package/recipes/spacevim.sh index 26ac32ba..bfd97682 100644 --- a/scripts/package/recipes/spacevim.sh +++ b/scripts/package/recipes/spacevim.sh @@ -2,7 +2,7 @@ set -euo pipefail package::is_installed() { - cat "$HOME/.config/nvim/init.vim" 2>/dev/null | grep -q "space-vim" 2>/dev/null + cat "${HOME}/.config/nvim/init.vim" 2>/dev/null | grep -q "spacevim" } package::install() { diff --git a/scripts/phabricator/arcx b/scripts/phabricator/arcx new file mode 100755 index 00000000..c0b6c7bc --- /dev/null +++ b/scripts/phabricator/arcx @@ -0,0 +1,167 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/core/main.sh" + +# ====================== +# wrappers +# ====================== + +_arc() { + debug arc "$@" + arc "$@" +} + +arc_diff() { + local argv=() title="" summary="" jira="" template="" create_fast=false + + while [[ $# -gt 0 ]]; do + case $1 in + --title) title="$2"; shift 2 ;; + --summary) summary="$2"; shift 2 ;; + --jira) jira="$2"; shift 2 ;; + --template) template="$2"; shift 2 ;; + --create-fast) create_fast=true; shift ;; + *) argv+=("$1"); shift ;; + esac + done + set -- "${argv[@]}" + + if [ -n "$title" ] || [ -n "$summary" ] || [ -n "$jira" ]; then + local -r tmpfile="$(mktmpfile)" + interpolated_revision_message "$title" "$summary" "$jira" > "$tmpfile" + argv+=("--message-file") + argv+=("$tmpfile") + fi + + if $create_fast; then + to_append=(--excuse ci --add-all --amend-all --autoland --ignore-unsound-tests --nointeractive --nounit --nolint --create) + # shellcheck disable=SC2206 + argv=(${argv[@]} ${to_append[@]}) + fi + + if [ -n "$template" ]; then + local -r tmpfile="$(mktmpfile)" + editor_source_code "$template" "${EDITOR:-vi}" >> "$tmpfile" + chmod +x "$tmpfile" + log::warn "export EDITOR=\"$tmpfile\"" + export EDITOR="$tmpfile" + fi + + _arc diff "${argv[@]}" +} + +arc_help() { + if [ $# = 0 ]; then + _arc --help + else + _arc help "$@" + fi +} + +# ====================== +# revision message +# ====================== + +interpolated_revision_message() { + local -r title="$1" + local -r summary="$2" + local -r jira="$3" + + cat <<EOF +${title} + +Summary: ${summary} + +Test Plan: + +Reviewers: + +Subscribers: + +Tags: + +Revert Plan: + +JIRA Issues: ${jira} + +API Changes: + +Monitoring and Alerts: +EOF +} + +editor_source_code() { + local -r template="$1" + local -r title="$1" + local -r editor="$2" + + cat <<EOF +#!/usr/bin/env bash +set -euo pipefail + +main() { + local -r msgfile="\${1:-}" + rm "\$msgfile" + cp "$template" "\$msgfile" + "$editor" "\$msgfile" || true +} + +main "\$@" +EOF +} + +# ====================== +# help message +# ====================== + +show_help() { + echo "$(log::ansi --magenta "arcx") + +$(log::ansi --yellow Warning:) this has only been tested on Linux and on OSX with GNU tools + +$(log::ansi --blue "Usage:") +$(log::ansi --bold diff) [<args>...] Extension to \`arc diff\` +$(log::ansi --bold help) [<args>...] Show arc's original help messages +$(log::ansi --bold --help) Show this help message +$(log::ansi --bold "<cmd>") [<args>...] Call to \`arc <cmd>\` + +$(log::ansi --blue "Extra arguments for \`arcx diff\`:") +$(log::ansi --bold --title) <string> Skip the revision message edit screen, including the diff title +$(log::ansi --bold --summary) <string> Skip the revision message edit screen, including the diff summary +$(log::ansi --bold --jira) <string> Skip the revision message edit screen, including the diff JIRA ticket +$(log::ansi --bold --create-fast) Use an opinionated list of arc args to create a new diff as fast as possible +$(log::ansi --bold --template) <path> Use a different template for revision messages + +$(log::ansi --blue "Examples:") +arcx diff --create-fast --title \"Add new feature\" --jira XYZ-123 +arcx diff --create --template mytemplate.txt" +} + +# ====================== +# low-level helpers +# ====================== + +mktmpfile() { + tmpfile="$(mktemp)" + trap 'rm -f -- "$tmpfile"' INT TERM HUP EXIT + echo "$tmpfile" +} + +# ====================== +# main +# ====================== + +main() { + local -r fn="${1:-"--help"}" + shift || true + + case "$fn" in + "diff") arc_diff "$@" ;; + "help") arc_help "$@" ;; + "--help") show_help ;; + *) _arc "$@" ;; + esac +} + +main "$@" diff --git a/scripts/raycast/aux/brightness.csv b/scripts/raycast/aux/brightness.csv new file mode 100644 index 00000000..cb3e7d48 --- /dev/null +++ b/scripts/raycast/aux/brightness.csv @@ -0,0 +1,5 @@ +level,n +Min,1 +Low,10 +Medium,50 +Max,100 diff --git a/scripts/raycast/aux/brightness.template.sh b/scripts/raycast/aux/brightness.template.sh new file mode 100644 index 00000000..c94b2d9b --- /dev/null +++ b/scripts/raycast/aux/brightness.template.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash --norc --noprofile + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title ${level} +# @raycast.mode silent + +# Optional parameters: +# @raycast.icon /Users/denis.isidoro/Pictures/Icons/brightness.png +# @raycast.packageName Brightness + +# Documentation: +# @raycast.description Brightness ${level} +# @raycast.author Denis Isidoro +# @raycast.authorURL https://denisidoro.github.io + +"${HOME}/dotfiles/bin/dot" system display q 1 -b "$n" -c "$n" diff --git a/scripts/raycast/gen b/scripts/raycast/gen index 8c665875..38f44559 100755 --- a/scripts/raycast/gen +++ b/scripts/raycast/gen @@ -65,7 +65,7 @@ main() { rm ./gen*.sh || true # ignored: "yabai" - for n in "bookmark" "focus_tab"; do + for n in "bookmark" "focus_tab" "brightness"; do gen "$n" done } diff --git a/scripts/rust/aux/core.bash b/scripts/rust/aux/core.bash new file mode 100644 index 00000000..fd5f7d64 --- /dev/null +++ b/scripts/rust/aux/core.bash @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/core/main.sh" + +# ===================== +# main +# ===================== + +if [ -z "${PROJ_NAME:-}" ]; then + die "PROJ_NAME is empty" +fi + +export PROJ_BIN_NAME="${PROJ_BIN_NAME:-$PROJ_NAME}" + +export PROJ_HOME="${PROJ_HOME:-"$(pwd)"}" + +# ===================== +# android +# ===================== + +export ANDROID_HOST="${ANDROID_HOST:-192.168.0.12}" +export ANDROID_PORT="${ANDROID_PORT:-8022}" + + +# ===================== +# paths +# ===================== + +export CARGO_DEFAULT_BIN="${HOME}/.cargo/bin" +export BIN_DIR="${BIN_DIR:-"$CARGO_DEFAULT_BIN"}" diff --git a/scripts/rust/build-android b/scripts/rust/build-android new file mode 100755 index 00000000..44d8e1cc --- /dev/null +++ b/scripts/rust/build-android @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/rust/aux/core.bash" + +main() { + "${PROJ_HOME}/scripts/release" aarch64-linux-android +} + +main "$@" \ No newline at end of file diff --git a/scripts/rust/fix b/scripts/rust/fix new file mode 100755 index 00000000..97a04c67 --- /dev/null +++ b/scripts/rust/fix @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/rust/aux/core.bash" + +_commit() { + if [ -n "${DOTFILES:-}" ]; then + git add --all || true + dot git commit am || true + fi +} + +cd "$PROJ_HOME" + +_commit +log::note "cargo fix..." +cargo fix || true + +_commit +log::note "cargo fmt..." +cargo fmt || true + +_commit +log::note "clippy..." +cargo clippy --fix || true + +# _commit +# log::note "dot code beautify..." +# find scripts -type f | xargs -I% dot code beautify % || true +# dot code beautify "${PROJ_HOME}/tests/run" || true diff --git a/scripts/rust/push-android b/scripts/rust/push-android new file mode 100755 index 00000000..c9e8b05d --- /dev/null +++ b/scripts/rust/push-android @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/rust/aux/core.bash" + +main() { + set -x + rsync \ + -e "ssh -p ${ANDROID_PORT}" \ + "${PROJ_HOME}/target/aarch64-linux-android/release/${PROJ_BIN_NAME}" \ + "${ANDROID_HOST}:/data/data/com.termux/files/home/${PROJ_BIN_NAME}" +} + +main "$@" \ No newline at end of file diff --git a/scripts/rust/release b/scripts/rust/release new file mode 100755 index 00000000..3436fcba --- /dev/null +++ b/scripts/rust/release @@ -0,0 +1,98 @@ +#!/usr/bin/env bash +set -euo pipefail + +##? release + +source "${DOTFILES}/scripts/rust/aux/core.bash" + +is_windows() { + local -r target="$1" + echo "$target" | grep -q "windows" +} + +get_env_target() { + eval "$(rustc --print cfg | grep target)" + local -rr raw="${target_arch:-}-${target_vendor:-}-${target_os:-}-${target_env:-}" + log::note "env target raw: $raw" + if echo "$raw" | grep -q "x86_64-apple-macos"; then + echo "x86_64-apple-darwin" + else + echo "$raw" + fi +} + +_tap() { + log::note "$@" + "$@" +} + +release() { + local -r env_target="$(get_env_target)" + log::note "env target: $env_target" + + local -r cross_target="${1:-"$env_target"}" + log::note "desired target: $cross_target" + + TAR_DIR="${PROJ_HOME}/target/tar" + local use_zip=false + local cross=true + + if [[ "$cross_target" == "$env_target" ]]; then + cross=false + fi + + cd "$PROJ_HOME" + + rm -rf "${PROJ_HOME}/target" 2> /dev/null || true + + if $cross; then + cargo install cross 2> /dev/null || true + _tap cross build --release --target "$cross_target" # --locked + local -r bin_folder="${cross_target}/release" + else + _tap cargo build --release # --locked + local -r bin_folder="release" + fi + + _ls "${bin_folder}" + + if is_windows "$cross_target"; then + local -r exe_ext=".exe" + use_zip=true + else + local -r exe_ext="" + fi + + bin_path="${PROJ_HOME}/target/${bin_folder}/${PROJ_BIN_NAME}${exe_ext}" + + chmod +x "$bin_path" + mkdir -p "$TAR_DIR" 2> /dev/null || true + + if upx --best --lzma "$bin_path"; then + echo "upx succeeded" + else + echo "upx failed" + fi + + cp "$bin_path" "$TAR_DIR" + + cd "$TAR_DIR" + + if $use_zip; then + zip -r "${PROJ_BIN_NAME}.zip" ./* + echo ::set-output name=EXTENSION::zip + else + tar -czf "${PROJ_BIN_NAME}.tar.gz" ./* + echo ::set-output name=EXTENSION::tar.gz + fi + + _ls "${bin_path}" + _ls "${TAR_DIR}" +} + +_ls() { + log::note "contents from $*:" + ls -la "$@" || true +} + +release "$@" diff --git a/scripts/rust/run b/scripts/rust/run new file mode 100755 index 00000000..af7cf628 --- /dev/null +++ b/scripts/rust/run @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/rust/aux/core.bash" + +main() { + local f="${PROJ_HOME}/target/debug/${PROJ_BIN_NAME}" + if [ -f "$f" ]; then + "$f" "$@" + return 0 + fi + + f="${PROJ_HOME}/target/release/${PROJ_BIN_NAME}" + if [ -f "$f" ]; then + "$f" "$@" + return 0 + fi + + if command_exists "${PROJ_BIN_NAME}"; then + "${PROJ_BIN_NAME}" "$@" + return 0 + fi + + cd "$PROJ_HOME" + cargo run -- "$@" +} + +main "$@" \ No newline at end of file diff --git a/scripts/rust/ssh-android b/scripts/rust/ssh-android new file mode 100755 index 00000000..9e8a3bec --- /dev/null +++ b/scripts/rust/ssh-android @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/rust/aux/core.bash" + +main() { + ssh -p "$ANDROID_PORT" "$ANDROID_HOST" "$@" +} + +main "$@" diff --git a/scripts/rust/tag b/scripts/rust/tag new file mode 100755 index 00000000..0448c3f8 --- /dev/null +++ b/scripts/rust/tag @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/rust/aux/core.bash" + +version_from_toml() { + cat "${PROJ_HOME}/Cargo.toml" \ + | grep version \ + | head -n1 \ + | awk '{print $NF}' \ + | tr -d '"' \ + | tr -d "'" +} + +main() { + cd "$PROJ_HOME" + + version="${1:-$(version_from_toml)}" + log::note "version: $version..." + sleep 2 + + git tag -a "v${version}" + git push origin --tags +} + +main "$@" \ No newline at end of file diff --git a/scripts/rust/termux-run b/scripts/rust/termux-run new file mode 100755 index 00000000..f7da3499 --- /dev/null +++ b/scripts/rust/termux-run @@ -0,0 +1,34 @@ +#!/bin/bash +set -euo pipefail + +export PROJ_BIN_NAME="__BIN_NAME__" + +main() { + local -r config="${1//@/\"}" + shift || true + + local args="$*" + args="${args//\//_}" + args="${args:0:64}" + + local -r tasker_tmp="${TASKER_TMP:-"/sdcard/Tasker/tmp"}" + local -r timestamp="$(date +"%Y-%m-%dT%H-%M-%S")" + local log="${tasker_tmp}/${PROJ_BIN_NAME}_${args}_${timestamp}.txt" + log="${log//[^0-9a-zA-Z_/]/_}" + + mkdir -p "$tasker_tmp" &>/dev/null || true + + for i in "$@"; do + case "$i" in + "%"*) + echo "aborting because of undefined input" > "$log" + exit 1 + ;; + esac + done + + local -r proj_bin="${PROJ_BIN:-"${HOME}/${PROJ_BIN_NAME}"}" + "$proj_bin" --config <(echo "$config") "$@" |& tee "$log" +} + +main "$@" \ No newline at end of file diff --git a/scripts/script/dashed b/scripts/script/dashed index a6f1e7cf..0c469726 100755 --- a/scripts/script/dashed +++ b/scripts/script/dashed @@ -2,6 +2,7 @@ set -euo pipefail source "${DOTFILES}/scripts/core/main.sh" +source "${DOTFILES}/scripts/core/platform.sh" ##? Use current path as argument if none is specified ## @@ -29,18 +30,33 @@ indexof() { echo -1; } +get_fn() { + IFS=',' read -r -a args <<< "$1" + platform::existing_command "${args[@]}" +} + dot_or_args() { local -r dash_index="$(indexof "--" "$@")" - # shellcheck disable=SC2124 - readonly fn="${@:1:$((dash_index-1))}" + + local args=() + args=("${@:2:$((dash_index-2))}") + + local -r fn1s="$1" + local -r fn1="$(get_fn "$fn1s")" + shift "$dash_index" - if [[ $# -lt 1 ]]; then - # shellcheck disable=SC2068 - ${fn[@]} . - else - # shellcheck disable=SC2068 - ${fn[@]} "$@" + + # echo "len args: ${#args[@]}; len @: $#" + # echo "args[0]: ${args[0]:-nil}" + + if [ $# -lt 1 ]; then + set -- "." fi + + args=("${args[@]}" "$@") + + # set -x + "$fn1" "${args[@]:-}" } -dot_or_args "$@" \ No newline at end of file +dot_or_args "$@" diff --git a/scripts/script/eval b/scripts/script/eval index becfc3b5..23ea4181 100755 --- a/scripts/script/eval +++ b/scripts/script/eval @@ -11,6 +11,19 @@ source "${DOTFILES}/scripts/core/main.sh" doc::maybe_help "$@" main() { + if [ "${1:-}" = "--load" ]; then + local -r load="$2" + shift 2 + + ifs=$IFS + IFS=':' + for l in $load; do + # shellcheck disable=SC1090 + source "${DOTFILES}/scripts/core/${l}.sh" + done + IFS=$ifs + fi + "$@" } diff --git a/scripts/script/yaml b/scripts/script/yaml new file mode 100755 index 00000000..0d1c025f --- /dev/null +++ b/scripts/script/yaml @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +##? YAML parser +##? +##? Usage: +##? yaml +##? +##? Examples: +##? eval "$(yaml my.yaml yaml_)" + +source "${DOTFILES}/scripts/core/main.sh" +doc::maybe_help "$@" + +main() { + # echoerr "reading yaml!" + + local -r prefix=$2 + local -r s='[[:space:]]*' + local -r w='[a-zA-Z0-9_]*' + local -r fs=$(echo @|tr @ '\034') + + sed "h;s/^[^:]*//;x;s/:.*$//;y/-/_/;G;s/\n//" "$1" | + sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \ + -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" | + awk -F "$fs" '{ + indent = length($1)/2; + vname[indent] = $2; + + for (i in vname) {if (i > indent) {delete vname[i]}} + if (length($3) > 0) { + vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")} + printf("export %s%s%s=\"%s\"\n", "'"$prefix"'",vn, $2, $3); + } + }' +} + +main "$@" \ No newline at end of file diff --git a/scripts/script/zsh b/scripts/script/zsh index 5f5fe734..d1cb058d 100755 --- a/scripts/script/zsh +++ b/scripts/script/zsh @@ -21,7 +21,7 @@ case "${1:-}" in echo "👌 Done!" ;; *perf*|bench*) - DOT_ZIM=false _benchmark + DOT_THEME=none _benchmark _benchmark ;; *comp*) diff --git a/scripts/security/store b/scripts/security/store index 110c97e4..0c261da6 100755 --- a/scripts/security/store +++ b/scripts/security/store @@ -135,7 +135,7 @@ main() { if has "$cmd"; then "$cmd" "$@" else - doc::help_msg "$0" + doc::_help_msg "$0" exit 1 fi } diff --git a/scripts/self/docker b/scripts/self/docker index 8583c1d0..64f4bac3 100755 --- a/scripts/self/docker +++ b/scripts/self/docker @@ -10,15 +10,14 @@ source "${DOTFILES}/scripts/core/main.sh" doc::maybe_help "$@" -if ${1:-install}; then - SCRIPT="EDITOR=cat dot self install" -else - SCRIPT=":" -fi +case "${1:-}" in + install) SCRIPT="DOT_INSTANCE=devpod /root/dotfiles/bin/dot self install --profile devpod" ;; + *) SCRIPT=":" ;; +esac docker run \ -it \ --entrypoint /bin/bash \ - -v "${DOTFILES}:/dotfiles" \ + -v "${DOTFILES}:/root/dotfiles" \ "bashell/alpine-bash" \ - -c "export DOTFILES=/dotfiles; export EDITOR=vi; export PATH=${PATH}:/dotfiles/bin; $SCRIPT; bash" + -c "$SCRIPT; bash" diff --git a/scripts/self/edit b/scripts/self/edit new file mode 100755 index 00000000..156bdcea --- /dev/null +++ b/scripts/self/edit @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/core/main.sh" + +##? Edit itself +##? +##? Usage: +##? edit instance <instance> + +doc::maybe_help "$@" + +_instance() { + local -r instance="$1" + local -r filename="${DOTFILES}/shell/aux/vars.bash" + sed -i -E 's/DOT_INSTANCE.*/DOT_INSTANCE="'"$instance"'"/' "$filename" +} + +main() { + case "${1:-}" in + instance) _instance "$2" ;; + *) exit 1 ;; + esac +} + +main "$@" \ No newline at end of file diff --git a/scripts/self/health b/scripts/self/health new file mode 100755 index 00000000..10c3a883 --- /dev/null +++ b/scripts/self/health @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/core/main.sh" + +##? Self health +##? +##? Usage: +##? health + +doc::maybe_help "$@" + +no="$(log::ansi --red no)" +yes="$(log::ansi --green yes)" + +ls_batch() { + echoerr + local -r batch="$1" + log::info "batch $batch" + for dep in $(dot pkg batch list "$batch"); do + local bool="$no" + if has "$dep"; then + bool="$yes" + elif dot pkg check "$dep" &>/dev/null; then + bool="$yes" + fi + printf "%-20s %s\n" "$dep" "$bool" + done +} + +main() { + ls_batch "nano" + ls_batch "mini" + ls_batch "dev" + ls_batch "full" +} + +main "$@" diff --git a/scripts/self/install b/scripts/self/install index 74e02a2b..0b7ef409 100755 --- a/scripts/self/install +++ b/scripts/self/install @@ -1,80 +1,81 @@ #!/usr/bin/env bash set -euo pipefail -export DOTFILES="${DOTFILES:-$HOME/dotfiles}" -export PATH="${DOTFILES}/bin:${PATH}" +export DOTFILES="${DOTFILES:-"${HOME}/dotfiles"}" +export PATH="${DOTFILES}/bin:${PATH}:/usr/local/bin:/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:${HOME}/bin" + REPO="https://github.com/denisidoro/dotfiles.git" DOT_BIN="${DOTFILES}/bin/dot" ##? Setups the environment ##? ##? Usage: -##? install +##? install [--profile <profile>] +##? +##? Profiles: +##? work +##? desktop +##? termux +##? devpod ##? ##? Env vars: ##? DOTFILES -##? DOT_VERSION -##? DOT_SKIP_PM_UPDATE +##? DOT_PM_UPDATE ##? DOT_SKIP_CORE_DEPS ##? DOT_SKIP_UPDATE ##? DOT_GIT_NAME ##? DOT_GIT_EMAIL ##? DOT_DOCOPT -##? DOT_FRE -##? DOT_FZF -##? DOT_NAVI -##? DOT_ZIM ##? DOT_THEME ##? DOT_LINK_EXTRA_ARG ##? DOT_ZSHRC_EXTRA ##? EDITOR ##? ##? Examples: -##? DOTFILES="$PWD/dotfiles" DOT_VERSION=master https://raw.githubusercontent.com/denisidoro/dotfiles/master/scripts/self/install +##? DOTFILES="$PWD/dotfiles" https://raw.githubusercontent.com/denisidoro/dotfiles/master/scripts/self/install +profile="devpod" case "${1:-}" in -h|--help|--version) grep "^##?" "$0" | cut -c 5-; exit 0 ;; + --profile) profile="$2" ;; esac _dot() { "$DOT_BIN" "$@" } -_has() { +has() { type "$1" &>/dev/null } -_install_git() { - sudo apt-get install git \ - || sudo yum install git \ - || brew install git \ - || sudo apk install git \ - || sudo pkg install git +_install() { + sudo apt-get install "$1" \ + || sudo yum install "$1" \ + || brew install "$1" \ + || sudo apk install "$1" \ + || sudo pkg install "$1" } -if ! _has sudo; then - sudo() { "$@"; } - export -f sudo -fi - clone_repo() { if ! has git; then - _install_git &>/dev/null + _install git fi + git clone "$REPO" "$DOTFILES" --depth 1 } -# TODO: use curl + zip file in case DOT_VERSION follow the pattern v20.* +if ! has sudo; then + sudo() { "$@"; } + export -f sudo +fi + main() { - # let's assume this is being called by a script if we're specifying a version - if [ -n "${DOT_VERSION:-}" ]; then - [ -n "${DOT_SKIP_PM_UPDATE:-}" ] || export DOT_SKIP_PM_UPDATE=true - [ -n "${DOT_SKIP_CORE_DEPS:-}" ] || export DOT_SKIP_CORE_DEPS=true - [ -n "${DOT_SKIP_SKIP_UPDATE:-}" ] || export DOT_SKIP_UPDATE=true - fi + export DOT_PM_UPDATE=${DOT_PM_UPDATE:-false} + export DOT_SKIP_CORE_DEPS=${DOT_SKIP_CORE_DEPS:-false} + export DOT_INSTANCE=${DOT_INSTANCE:-devpod} if [ -x "$DOT_BIN" ]; then - : + echo "dotfiles already cloned!" elif [ -d "$DOTFILES" ]; then echo "Backing up existing dotfiles folder and cloning new dotfiles..." local -r old_dotfiles=$(mktemp -u -d "${DOTFILES}_XXXX") @@ -87,53 +88,87 @@ main() { cd "$DOTFILES" - # Use specific version - if [ -n "${DOT_VERSION:-}" ] && [ "$DOT_VERSION" != "master" ]; then - git checkout "${DOT_VERSION}" - _dot self install "$@" - exit 0 - fi + # Install some key dependencies + _dot pkg add git curl wget - # Make sure everything is up to date - if ! ${DOT_SKIP_PM_UPDATE:-false}; then - if _has apt-get; then - sudo apt-get upgrade || true - sudo apt-get update || true - fi - if _has brew; then - brew update || true - fi + # Android bootstrap + if uname -a | grep -q "ndroid"; then + pkg install ncurses-utils + _dot pkg add termux-essentials fi - if ! ${DOT_SKIP_CORE_DEPS:-false}; then - # Install some key dependencies - _dot pkg add git curl wget || true - - # Android bootstrap - if uname -a | grep -q "ndroid"; then - pkg install ncurses-utils || true - _dot pkg add termux-essentials || true - fi + # OSX bootstrap + if uname -s | grep -q "arwin"; then + _dot pkg add xcode-select brew gnu + fi - # OSX bootstrap - if uname -s | grep -q "arwin"; then - xcode-select --install || true - _dot pkg add brew || true - _dot pkg add gnu || true + # Make sure everything is up to date + if $DOT_PM_UPDATE; then + if has apt-get; then + sudo apt-get upgrade + sudo apt-get update + elif has brew; then + brew update fi fi - # call setup - if ! ${DOT_SKIP_UPDATE:-false}; then - _dot self update + # Some setup + _dot pkg add dot-folders + _dot pkg add dot-gitconfig + _dot pkg add dot-zshrc + + # Machine-specific setup + _dot self edit instance "$DOT_INSTANCE" + + # Symlinks + _dot self update + + # Misc + fix_locales + + # Reload + hash -r &>/dev/null + # shellcheck disable=SC1091 + source "${HOME}/.bashrc" &>/dev/null + hash -r &>/dev/null +} + +fix_locales() { + if has locale-gen; then + echo "Fixing locales..." + locale-gen en_US en_US.UTF-8 fi } -main "$@" +echo "Install using profile ${profile}!" + +set +e + +case "$profile" in + "devpod") + export EDITOR=cat + export TERM=dumb + export DOT_THEME=none + export DOT_DOCOPT=python + export DOT_INSTANCE="devpod" + export DOT_PKG_ALLOW_BUILD=false + export DOT_LINK_EXTRA_ARG='--backup' + export DOTLINK_IGNORE_LIST="git/config,zshrc,bashrc" + + sudo mkdir -p "${HOME}/.cache" + sudo chmod 777 "${HOME}/.cache" + + main "$@" + + _dot pkg batch add mini + _dot pkg add dot-source-shellrc + ;; + *) + DOT_INSTANCE="$profile" + main "$@" + ;; +esac + +set -e -hash -r &>/dev/null || true -# shellcheck disable=SC1091 -source "${HOME}/.bashrc" &>/dev/null || true -# shellcheck disable=SC1091 -source "${HOME}/.zshrc" &>/dev/null || true -hash -r &>/dev/null || true +_dot self health diff --git a/scripts/self/install-no-interactive b/scripts/self/install-no-interactive deleted file mode 100755 index 86ca3e61..00000000 --- a/scripts/self/install-no-interactive +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -source "${DOTFILES}/scripts/core/main.sh" - -##? Install dotfiles without asking for input -##? -##? Usage: -##? install-no-interactive - -doc::maybe_help "$@" - -EDITOR=cat \ - TERM=dumb \ - DOT_ZIM=false \ - DOT_THEME=none \ - DOT_DOCOPT=python \ - DOT_FRE=false \ - DOT_FZF=false \ - DOT_NAVI=false \ - DOT_ZIM=false \ - DOT_LINK_EXTRA_ARG='--backup' \ - DOT_SKIP_PM_UPDATE=true \ - DOT_SKIP_CORE_DEPS=true \ - dot self install diff --git a/scripts/self/test b/scripts/self/test index f1315d4d..0231d393 100755 --- a/scripts/self/test +++ b/scripts/self/test @@ -85,6 +85,7 @@ mkdir -p "$TEST_DIR" 2>/dev/null || true _prepare_zsh 2>/dev/null || true _prepare_dotlink 2>/dev/null || true _stub_vscode 2>/dev/null || true + export PATH="${DOTFILES}/local/bin:${PATH}" hash -r 2>/dev/null || true diff --git a/scripts/self/update b/scripts/self/update index 1fa31e3a..59d307c2 100755 --- a/scripts/self/update +++ b/scripts/self/update @@ -25,11 +25,6 @@ main() { log::info "Current config: $tags" echoerr - _add dot-git || true - _add dot-folders || true - _add dot-gitconfig || true - _add dot-zshrc || true - echoerr log::info "Setting symlinks..." update_dotfiles_common @@ -41,14 +36,6 @@ main() { has_tag "$tags" "wsl" && update_dotfiles_wsl has_tag "$tags" "work" && update_dotfiles_work - fix_locales || true - - if ! ${DOT_SKIP_CORE_DEPS:-false}; then - if has zimfw && zimfw install; then - zimfw update || true - fi - fi - set -e echoerr @@ -72,17 +59,6 @@ _add() { dot pkg add "$@" } -# ============================== -# Locale -# ============================== - -fix_locales() { - if has locale-gen; then - echoerr - log::info "Fixing locales..." - locale-gen en_US en_US.UTF-8 - fi -} # ============================== # Symlinks and custom configs @@ -90,15 +66,17 @@ fix_locales() { update_dotfiles() { params=() + if [ -n "${DOT_LINK_EXTRA_ARG:-}" ]; then params+=("$DOT_LINK_EXTRA_ARG") fi - DOTLINK="${1:-unix}" dot self link set --create-dirs --verbose "${params[@]:-}" + + DOTLINK="$1" dot self link set --create-dirs --verbose "${params[@]:-}" } update_dotfiles_common() { log::info "Symlinking for Unix..." - update_dotfiles + update_dotfiles "unix" } update_dotfiles_osx() { @@ -147,5 +125,5 @@ hash -r &>/dev/null || true # shellcheck disable=SC1091 source "${HOME}/.bashrc" &>/dev/null || true # shellcheck disable=SC1091 -source "${HOME}/.zshrc" &>/dev/null || true +# source "${HOME}/.zshrc" &>/dev/null || true hash -r &>/dev/null || true diff --git a/scripts/storm/camera b/scripts/storm/camera index 2393a40e..3bd0aea5 100755 --- a/scripts/storm/camera +++ b/scripts/storm/camera @@ -1,6 +1,5 @@ #!/usr/bin/env bash set -euo pipefail -set -x source "${DOTFILES}/scripts/storm/aux/core.sh" source "${DOTFILES}/scripts/core/main.sh" @@ -8,11 +7,11 @@ source "${DOTFILES}/scripts/core/main.sh" ##? Camera utilities ##? ##? Usage: -##? camera pull -##? camera set -##? camera push +##? camera pull <args...> +##? camera set <args...> +##? camera push <args...> -doc::parse "$@" +doc::maybe_help --show-if-no-args "$@" export BOXTMP_PHONE="${STORM}/boxtmp/phone" @@ -22,21 +21,18 @@ _pull() { } _set() { - dot storm run set-camera-buffers + dot storm run "$@" set-camera-buffers } _push() { - dot storm upload + dot storm upload "$@" } handler() { - if $pull; then - _pull "$@" - elif $set; then - _set "$@" - elif $push; then - _push "$@" - fi + local -r fn="$1" + shift + + "_${fn}" "$@" } main() { @@ -47,7 +43,8 @@ main() { fi dot fs remove-empty-dirs "$STORM" || true - dot fs remove-empty-dirs "$PICTURES" || true + dot fs remove-empty-dirs "$PICTURES/Camera" || true + dot fs remove-empty-dirs "$PICTURES/VVCamera" || true return $errors } diff --git a/scripts/cloud/check b/scripts/storm/check similarity index 100% rename from scripts/cloud/check rename to scripts/storm/check diff --git a/scripts/storm/fix-gps b/scripts/storm/fix-gps new file mode 100755 index 00000000..f744ff58 --- /dev/null +++ b/scripts/storm/fix-gps @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/storm/aux/core.sh" +source "${DOTFILES}/scripts/core/main.sh" + +##? Fix GPS coordinates in case lat/lng are glued +##? +##? Usage: +##? fix-gps myfile.mpg + +doc::maybe_help "$@" + +main() { + local -r filename="$1" + + local -r gps="$(exiftool -T -n "-gpsLatitude" "$filename" | sed 's/-0/;-0/g')" + + local -r lat=$(echo "$gps" | cut -d';' -f2) + local -r lng=$(echo "$gps" | cut -d';' -f3) + + if [[ $(echo "$lat >= -90" | bc) -ne "1" || $(echo "$lat <= 90" | bc) -ne "1" ]]; then + echoerr "invalid lat: $lat" + exit 1 + fi + + if [[ $(echo "$lng >= -180" | bc) -ne "1" || $(echo "$lng <= 180" | bc) -ne "1" ]]; then + echoerr "invalid lng: $lng" + exit 1 + fi + + exiftool -overwrite_original_in_place -gps:all= "$filename" || true + exiftool -overwrite_original_in_place "-gps*=" "$filename" || true + + set -x + exiftool -overwrite_original_in_place -gpsLatitude="$lat" -gpsLongitude="$lng" "$filename" + exiftool -T -n -gpsLatitude -gpsLongitude "$filename" +} + +main "$@" diff --git a/scripts/cloud/password b/scripts/storm/password similarity index 100% rename from scripts/cloud/password rename to scripts/storm/password diff --git a/scripts/storm/run b/scripts/storm/run index 8246f63b..a7107ddb 100755 --- a/scripts/storm/run +++ b/scripts/storm/run @@ -18,7 +18,7 @@ main() { local -r storm="$STORM" local -r telegramToken="$(dot security store get telegram/bot_token)" local -r telegramChatId="$(dot security store get "$TELEGRAM_CHAT_KEY")" - local -r cryptoPassword="$(dot security store get cloud/password)" + local -r cryptoPassword="${CRYPTO_PASSWORD:-$(dot security store get cloud/password)}" local -r yaml="$(cat <<EOF crypto: @@ -117,11 +117,12 @@ archive: EOF )" + # storm --config <(echo "$yaml") "$@" + local -r temp_file=$(mktemp) echo "$yaml" > "$temp_file" + # set -x storm --config "$temp_file" "$@" - - # storm --config <(echo "$yaml") "$@" } main "$@" \ No newline at end of file diff --git a/scripts/storm/upload b/scripts/storm/upload index fce91508..cb7f90c5 100755 --- a/scripts/storm/upload +++ b/scripts/storm/upload @@ -1,6 +1,5 @@ #!/usr/bin/env bash set -euo pipefail -set -x source "${DOTFILES}/scripts/storm/aux/core.sh" source "${DOTFILES}/scripts/core/main.sh" diff --git a/scripts/cloud/zip b/scripts/storm/zip similarity index 100% rename from scripts/cloud/zip rename to scripts/storm/zip diff --git a/scripts/system/display b/scripts/system/display index 64c1974f..39e2c232 100755 --- a/scripts/system/display +++ b/scripts/system/display @@ -55,6 +55,7 @@ _osx_external() { args+=("-bg" "$blue_gain") fi + set -x "${args[@]}" } @@ -85,6 +86,7 @@ _osx_internal() { _unsupported "Blue gain" fi + set -x "${args[@]}" } diff --git a/scripts/telegram/message b/scripts/telegram/message new file mode 100755 index 00000000..871afe11 --- /dev/null +++ b/scripts/telegram/message @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -euo pipefail + +source "${DOTFILES}/scripts/core/main.sh" + +##? Sends a message to Telegram +##? +##? Usage: +##? message [options] <body> +##? +##? Options: +##? -c --chat <chat> Chat to receive the message [default: bot] +##? +##? Examples: +##? message --chat "foo bar" + +doc::parse "$@" + +main() { + export TELEGRAM_CHAT_KEY="${TELEGRAM_CHAT_KEY:-"telegram/${chat}_chat_id"}" + dot storm run send-telegram-message "$body" +} + +main "$@" diff --git a/scripts/url/mark b/scripts/url/mark deleted file mode 100755 index a6e4cdb2..00000000 --- a/scripts/url/mark +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -source "${DOTFILES}/scripts/core/main.sh" -source "${DOTFILES}/scripts/core/ini.sh" - -##? Bookmarks -##? -##? Usage: -##? mark <args>... -##? -##? Examples: -##? mark mail - -doc::maybe_help "$@" - -_url() { - cat "${DOTFILES}/local/marks.ini" | ini::get "$*" -} - -action=(dot terminal open) - -for u in $(_url "$*"); do - "${action[@]}" "$u" -done diff --git a/shell/aliases/core.bash b/shell/aliases/core.bash index 72fc64af..acebe1ea 100644 --- a/shell/aliases/core.bash +++ b/shell/aliases/core.bash @@ -4,22 +4,15 @@ # terminal # ======================== alias c='clear' -alias t='tmux' -alias faketty='dot terminal abra faketty' -alias rxout='dot terminal abra rxout' -alias rxerr='dot terminal abra rxerr' -alias txspl='dot terminal abra txspl' -alias rxls='dot terminal abra rxls' -txls() { eval "$(abra hook "$DOT_SHELL")"; } -alias bt='bat -p' -alias ansi='dot terminal ansi' +alias faketty='dot script faketty' +alias ansi='dot script ansi' alias icat="kitty +kitten icat --align=left" -alias ssh="kitty +kitten ssh" +# alias ssh="kitty +kitten ssh" # ======================== # shell # ======================== -alias reload='source "${HOME}/.${DOT_SHELL:-zsh}rc' # env -i zsh +alias reload='source "${HOME}/.$(basename $SHELL)rc"' # env -i zsh # ======================== # kitty @@ -34,10 +27,10 @@ alias map='xargs -I%' # ======================== # editors # ======================== -alias vim='nvim' -alias v="dot terminal dashed nvim --" -alias code='dot terminal dashed dot code vscode --' -alias e='code' +alias vim='v' +alias nvim='v' +alias vi='v' +alias code='e' # ======================== # utils @@ -46,7 +39,6 @@ alias e='code' alias d='dot' alias n="navi" alias browser="dot terminal open -b" -alias chrome="dot terminal open -b" alias color="dot terminal color" # ======================== @@ -57,11 +49,12 @@ source "${DOTFILES}/shell/aliases/git.bash" # ======================== # phabricator # ======================== -alias ac="arc diff --create --nounit --nolint" -alias ad="arc diff --nounit --nolint" +alias ac="arc diff --create --nounit --nolint --excuse=ci" +alias ad="arc diff --nounit --nolint --excuse=ci" alias au="navi best 'Update a diff'" alias al="navi best 'Land a diff'" uc() { navi --best-match --query "uber creds $@"; } +alias arcx="dot phabricator arcx" # ======================== # projects @@ -79,13 +72,9 @@ unalias f &> /dev/null alias lst="tree -L 2" cdd() { cd "$@" && ls .; } mkcd() { mkdir -p -- "$@" && cd -P -- "$@"; } -debug() { - dot shell log info "$@" - "$@" -} _safe_cd() { - [[ -z "${1:-}" ]] && return 1 || true + # [[ -z "${1:-}" ]] && return 1 || true [[ -d "${1:-}" ]] && cd "$1" || echoerr "$1 doesn't exist" } @@ -101,3 +90,14 @@ alias jv="dot fs jump edit global nvim" alias jjv="dot fs jump edit local nvim" alias js="dot fs jump edit global code" alias jjs="dot fs jump edit local code" + +# ======================== +# misc +# ======================== +alias pr='gpr' +alias mono="dot work mono" + +# debug() { +# dot shell log info "$@" +# "$@" +# } \ No newline at end of file diff --git a/shell/aliases/osx.bash b/shell/aliases/osx.bash new file mode 100644 index 00000000..d40f0dc2 --- /dev/null +++ b/shell/aliases/osx.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +alias xdg-open='open' diff --git a/shell/aux/vars.bash b/shell/aux/vars.bash index cd9ce50c..332a0f37 100644 --- a/shell/aux/vars.bash +++ b/shell/aux/vars.bash @@ -1,7 +1,10 @@ #!/usr/bin/env bash +# dotfiles +export DOT_INSTANCE="mac" + # default editor -export EDITOR='nvim' +export EDITOR='v' # default browser export BROWSER='vivaldi' @@ -23,10 +26,6 @@ export DEV_HOME="${HOME}/dev" # Clojure export LEIN_SUPPRESS_USER_LEVEL_REPO_WARNINGS=true -# Golang -export GOPATH="${DEV_HOME}/go" -export GOBIN="${GOPATH}/bin" - # package management export HOMEBREW_NO_AUTO_UPDATE=1 @@ -35,13 +34,6 @@ export FZF_DEFAULT_OPTS='--height 70% --reverse --inline-info --cycle' export FZF_DEFAULT_COMMAND='ag --hidden --ignore .git -g ""' export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" -# JS -export VOLTA_HOME="${HOME}/.volta" -export NVM_DIR="${HOME}/.nvm" - -# security -export GPG_TTY=$(tty) - # x11 export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-"${HOME}/.config"}" export XENVIRONMENT="${XENVIRONMENT:-"${HOME}/.Xresources"}" diff --git a/shell/aux/work_safe.bash b/shell/aux/work_public.bash similarity index 95% rename from shell/aux/work_safe.bash rename to shell/aux/work_public.bash index 2002b74e..69b758fc 100644 --- a/shell/aux/work_safe.bash +++ b/shell/aux/work_public.bash @@ -1,11 +1,7 @@ #!/usr/bin/env zsh export DOT_DOCOPT=${DOT_DOCOPT:-"docpars"} -export DOT_FZF=${DOT_FZF:-true} -export DOT_NAVI=${DOT_NAVI:-true} -export DOT_FRE=${DOT_FRE:-true} export DOT_THEME=${DOT_THEME:-powerlevel} -export DOT_ZIM=${DOT_ZIM:-true} export PATH="${PATH}:${WORK_BINARIES_PATH}:/usr/local/opt/bash/bin/:/usr/local/bin:${HOMEBREW_PREFIX}/sbin:${HOMEBREW_PREFIX}/bin" @@ -14,9 +10,17 @@ export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-11.0.11.jdk/Contents/Hom export NPM_CONFIG_REGISTRY="https://registry.npmjs.org/" export GOOGLE_CLOUD_SDK_HOME="${DEV_HOME}/google-cloud-sdk" -alias ls='exa --icons' +# JS +export VOLTA_HOME="${HOME}/.volta" +export NVM_DIR="${HOME}/.nvm" + +# Golang +export GOPATH="${DEV_HOME}/go" +export GOBIN="${GOPATH}/bin" -alias xdg-open='open' +source "${DOTFILES}/shell/aliases/osx.bash" + +alias ls='exa --icons' alias sed='gsed' alias awk='gawk' @@ -34,8 +38,7 @@ alias sort='gsort' alias kill='gkill' alias xargs='gxargs' alias base64='gbase64' -alias pr='gpr' -alias mono="dot work mono" + alias ysa="killall Dock; sudo yabai --install-sa; sudo yabai --load-sa" _load_work_stuff() { @@ -89,12 +92,12 @@ _load_work_stuff() { ;; bazel) dot script log info "Loading bazel..." - case ${DOT_SHELL:-} in + case "$(basename $SHELL)" in zsh) zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path ~/.zsh/cache ;; - *) source /usr/local/etc/bash_completion.d/bazel-complete.bash ;; + *) source /usr/local/etc/bash_completion.d/bazel-complete.bash || true ;; esac ;; virtualenv) diff --git a/shell/bash/bashrc b/shell/bash/bashrc index d0fc57bf..c00648cf 100644 --- a/shell/bash/bashrc +++ b/shell/bash/bashrc @@ -5,10 +5,7 @@ # fi # dotfiles -export DOTFILES="${DOTFILES:-$HOME/dotfiles}" - -# register which shell is running -export DOT_SHELL="bash" +export DOTFILES="${DOTFILES:-"${HOME}/dotfiles"}" # load vars source "${DOTFILES}/shell/aux/vars.bash" @@ -20,10 +17,8 @@ source "${DOTFILES}/shell/aux/core.bash" source "${DOTFILES}/shell/aliases/core.bash" # load local custom config -source "${DOTFILES}/local/zshrc" # 2> /dev/null || true +source "${DOTFILES}/local/zshrc" 2> /dev/null || true +source "${DOTFILES}/local/${DOT_INSTANCE}/zshrc" 2> /dev/null || true # theme source "${DOTFILES}/shell/themes/dns.bash" - -# [ -f ~/.fzf.bash ] && source ~/.fzf.bash -. "$HOME/.cargo/env" diff --git a/shell/themes/core.zsh b/shell/themes/core.zsh index 0ee45b23..afaf6d39 100644 --- a/shell/themes/core.zsh +++ b/shell/themes/core.zsh @@ -19,3 +19,11 @@ esac ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=cyan" ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20 ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) + +# case "${DOT_INSTANCE:-}" in +# devpod*) +# typeset -g POWERLEVEL9K_DIR_FOREGROUND=45 +# typeset -g POWERLEVEL9K_DIR_ANCHOR_FOREGROUND=81 +# typeset -g POWERLEVEL9K_PROMPT_CHAR_OK_{VIINS,VICMD,VIVIS,VIOWR}_FOREGROUND=34 +# ;; +# esac \ No newline at end of file diff --git a/shell/themes/p10k.zsh b/shell/themes/p10k.zsh index 0e7b5c2c..8632aa60 100644 --- a/shell/themes/p10k.zsh +++ b/shell/themes/p10k.zsh @@ -32,7 +32,7 @@ # The list of segments shown on the left. Fill it with the most important segments. typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=( # =========================[ Line #1 ]========================= - # os_icon # os identifier + os_icon # os identifier dir # current directory vcs # git status # =========================[ Line #2 ]========================= @@ -190,7 +190,7 @@ # Transparent background. typeset -g POWERLEVEL9K_PROMPT_CHAR_BACKGROUND= # Green prompt symbol if the last command succeeded. - typeset -g POWERLEVEL9K_PROMPT_CHAR_OK_{VIINS,VICMD,VIVIS,VIOWR}_FOREGROUND=31 # THEMECOLOR: 76 + typeset -g POWERLEVEL9K_PROMPT_CHAR_OK_{VIINS,VICMD,VIVIS,VIOWR}_FOREGROUND=31 # BKP: 76 # Red prompt symbol if the last command failed. typeset -g POWERLEVEL9K_PROMPT_CHAR_ERROR_{VIINS,VICMD,VIVIS,VIOWR}_FOREGROUND=196 # Default prompt symbol. @@ -211,17 +211,18 @@ ##################################[ dir: current directory ]################################## # Default current directory color. - typeset -g POWERLEVEL9K_DIR_FOREGROUND=219 # THEMECOLOR: 31 + typeset -g POWERLEVEL9K_DIR_FOREGROUND=219 # BKP: 31 + # If directory is too long, shorten some of its segments to the shortest possible unique # prefix. The shortened directory can be tab-completed to the original. typeset -g POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_unique # Replace removed segment suffixes with this symbol. typeset -g POWERLEVEL9K_SHORTEN_DELIMITER= # Color of the shortened directory segments. - typeset -g POWERLEVEL9K_DIR_SHORTENED_FOREGROUND=103 # THEMECOLOR?: 103 + typeset -g POWERLEVEL9K_DIR_SHORTENED_FOREGROUND=103 # BKP?: 103 # Color of the anchor directory segments. Anchor segments are never shortened. The first # segment is always an anchor. - typeset -g POWERLEVEL9K_DIR_ANCHOR_FOREGROUND=225 # THEMECOLOR: 39 + typeset -g POWERLEVEL9K_DIR_ANCHOR_FOREGROUND=225 # BKP: 39 # Display anchor directory segments in bold. typeset -g POWERLEVEL9K_DIR_ANCHOR_BOLD=true # Don't shorten directories that contain any of these files. They are anchors. @@ -365,9 +366,9 @@ if (( $1 )); then # Styling for up-to-date Git status. local meta='%246F' # grey foreground - local clean='%183F' # green foreground, THEMECOLOR: 36 - local modified='%252F' # yellow foreground, THEMECOLOR: 178 - local untracked='%74F' # blue foreground, THEMECOLOR: 39 + local clean='%183F' # green foreground, BKP: 36 + local modified='%252F' # yellow foreground, BKP: 178 + local untracked='%74F' # blue foreground, BKP: 39 local conflicted='%196F' # red foreground else # Styling for incomplete and stale Git status. @@ -462,7 +463,7 @@ typeset -g POWERLEVEL9K_VCS_{STAGED,UNSTAGED,UNTRACKED,CONFLICTED,COMMITS_AHEAD,COMMITS_BEHIND}_MAX_NUM=-1 # Icon color. - typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_COLOR=183 # THEMECOLOR: 76 + typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_COLOR=183 # BKP: 76 typeset -g POWERLEVEL9K_VCS_LOADING_VISUAL_IDENTIFIER_COLOR=244 # Custom icon. # typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_EXPANSION='⭐' diff --git a/shell/themes/prompt_dns_setup b/shell/themes/prompt_dns_setup index 761dc41f..2d448bb7 100644 --- a/shell/themes/prompt_dns_setup +++ b/shell/themes/prompt_dns_setup @@ -24,7 +24,7 @@ prompt_dns_precmd() { } prompt_dns_setup() { - local prompt_dns_status="%(?:%F${PROMPT_COLOR_1}$FIRST_CHARACTER_OK:%F{red}$FIRST_CHARACTER_KO)" + local prompt_dns_status="%(?:%F${PROMPT_COLOR_1}$FIRST_CHARACTER_OK:%F{red}$FIRST_CHARACTER_KO)%F{reset}" autoload -Uz add-zsh-hook && add-zsh-hook precmd prompt_dns_precmd diff --git a/shell/zsh/bindings/navi.zsh b/shell/zsh/bindings/navi.zsh index db00eff0..7e708fcb 100644 --- a/shell/zsh/bindings/navi.zsh +++ b/shell/zsh/bindings/navi.zsh @@ -1,4 +1,38 @@ #!/usr/bin/env zsh -eval "$(navi widget zsh)" +_navi_call() { + local result="$(navi "$@" </dev/tty)" + printf "%s" "$result" +} + +_navi_widget() { + local -r input="${LBUFFER}" + local -r last_command="$(echo "${input}" | navi fn widget::last_command)" + local replacement="$last_command" + + if [ -z "$last_command" ]; then + replacement="$(_navi_call --print)" + elif [ "$LASTWIDGET" = "_navi_widget" ] && [ "$input" = "$previous_output" ]; then + replacement="$(_navi_call --print --query "$last_command")" + else + replacement="$(_navi_call --print --best-match --query "$last_command")" + fi + + if [ -n "$replacement" ]; then + local -r find="${last_command}_NAVIEND" + previous_output="${input}_NAVIEND" + previous_output="${previous_output//$find/$replacement}" + else + previous_output="$input" + fi + + zle kill-whole-line + LBUFFER="${previous_output}" + region_highlight=("P0 100 bold") + zle redisplay +} + +zle -N _navi_widget +bindkey '^g' _navi_widget + return 0 diff --git a/shell/zsh/bindings/zim.zsh b/shell/zsh/bindings/zim.zsh index db6374fe..8045fad7 100644 --- a/shell/zsh/bindings/zim.zsh +++ b/shell/zsh/bindings/zim.zsh @@ -15,4 +15,23 @@ fi bindkey '^P' history-substring-search-up bindkey '^N' history-substring-search-down bindkey -M vicmd 'k' history-substring-search-up -bindkey -M vicmd 'j' history-substring-search-down \ No newline at end of file +bindkey -M vicmd 'j' history-substring-search-down + +# autocomplete +# sudo chmod g-w /usr/local/share/zsh/site-functions +# sudo chmod g-w /usr/local/share/zsh +# export POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE=false +# disable sort when completing `git checkout` +zstyle ':completion:*:git-checkout:*' sort false +# set descriptions format to enable group support +zstyle ':completion:*:descriptions' format '[%d]' +# set list-colors to enable filename colorizing +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} +# preview directory's content with exa when completing cd +zstyle ':fzf-tab:complete:cd:*' fzf-preview 'exa -1 --color=always $realpath' +# switch group using `,` and `.` +zstyle ':fzf-tab:*' switch-group ',' '.' + +# set path for completions +fpath=("${DOTFILES}/shell/zsh/completions" $fpath) +autoload -U compinit && compinit \ No newline at end of file diff --git a/shell/zsh/zshrc b/shell/zsh/zshrc index 9e1b1f4e..d10ceffc 100644 --- a/shell/zsh/zshrc +++ b/shell/zsh/zshrc @@ -1,21 +1,10 @@ #!/usr/bin/env zsh -# prevent multiple sourcing -# if [ -n "${DOT_SHELL:-}" ]; then -# return 0 -# fi - -# Powerlevel10k instant prompt -if [[ "$DOT_THEME" -eq "powerlevel" ]]; then - source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" -fi +# set +x # dotfiles export DOTFILES="${DOTFILES:-"${HOME}/dotfiles"}" -# register which shell is running -export DOT_SHELL="zsh" - # load vars source "${DOTFILES}/shell/aux/vars.bash" @@ -24,67 +13,51 @@ source "${DOTFILES}/shell/aux/core.bash" # load aliases source "${DOTFILES}/shell/aliases/core.bash" -# echoerr foo -# export -f echoerr # load local custom config -source "${DOTFILES}/local/zshrc" # 2> /dev/null || true - -# autocomplete -# sudo chmod g-w /usr/local/share/zsh/site-functions -# sudo chmod g-w /usr/local/share/zsh -# export POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE=false -# disable sort when completing `git checkout` -zstyle ':completion:*:git-checkout:*' sort false -# set descriptions format to enable group support -zstyle ':completion:*:descriptions' format '[%d]' -# set list-colors to enable filename colorizing -zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} -# preview directory's content with exa when completing cd -zstyle ':fzf-tab:complete:cd:*' fzf-preview 'exa -1 --color=always $realpath' -# switch group using `,` and `.` -zstyle ':fzf-tab:*' switch-group ',' '.' -# set path for completions -fpath=("${DOTFILES}/shell/zsh/completions" $fpath) -autoload -U compinit && compinit - -# zim -if ${DOT_ZIM:-false}; then - # source ${ZIM_HOME}/login_init.zsh -q &! - - # if [[ ${ZIM_HOME}/init.zsh -ot ${ZDOTDIR:-${HOME}}/.zimrc ]]; then - # # Update static initialization script if it's outdated, before sourcing it - # source ${ZIM_HOME}/zimfw.zsh init -q - # fi - - source ${ZIM_HOME}/init.zsh -fi +source "${DOTFILES}/local/zshrc" 2> /dev/null || true +source "${DOTFILES}/local/${DOT_INSTANCE}/zshrc" 2> /dev/null || true # on directory change -dns_chpwd() { - if ${DOT_FRE:-true}; then +if has fre; then + dns_chpwd() { fre --add "$PWD" - fi - # teleport tx --channel pwd --value "$PWD" & -} -typeset -gaU chpwd_functions -chpwd_functions+=dns_chpwd + } + typeset -gaU chpwd_functions + chpwd_functions+=dns_chpwd +fi # history setopt HIST_IGNORE_ALL_DUPS -# theme -source "${DOTFILES}/shell/themes/core.zsh" - # load bindings source "${DOTFILES}/shell/zsh/bindings/editing.zsh" -[[ ${DOT_NAVI:-false} ]] && source "${DOTFILES}/shell/zsh/bindings/navi.zsh" -[[ ${DOT_ZIM:-false} ]] && source "${DOTFILES}/shell/zsh/bindings/zim.zsh" -[[ ${DOT_FZF:-false} ]] && source "${DOTFILES}/shell/zsh/bindings/fzf.zsh" +has navi && source "${DOTFILES}/shell/zsh/bindings/navi.zsh" +has fzf && source "${DOTFILES}/shell/zsh/bindings/fzf.zsh" + +# theme +export DOT_THEME="${DOT_THEME:-none}" +# if [ "$DOT_THEME" != "none" ]; then + source "${DOTFILES}/shell/themes/core.zsh" +# fi # misc # WORDCHARS=${WORDCHARS//[\/]} +# zim +if [[ "$DOT_THEME" == "powerlevel" ]]; then + # source ${ZIM_HOME}/login_init.zsh -q &! + + # if [[ ${ZIM_HOME}/init.zsh -ot ${ZDOTDIR:-${HOME}}/.zimrc ]]; then + # # Update static initialization script if it's outdated, before sourcing it + # source ${ZIM_HOME}/zimfw.zsh init -q + # fi + + source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" + source "${ZIM_HOME}/init.zsh" + source "${DOTFILES}/shell/zsh/bindings/zim.zsh" +fi + # in order not to mess up with subshells export ZDOTDIR="$HOME" @@ -98,3 +71,5 @@ export ZDOTDIR="$HOME" # zmodload zsh/zprof (in /etc/zshenv) # zprof + +# set -x \ No newline at end of file diff --git a/termux/usb/usbtest.c b/termux/usb/usbtest.c deleted file mode 100644 index 9b635938..00000000 --- a/termux/usb/usbtest.c +++ /dev/null @@ -1,30 +0,0 @@ -/* -Original source: https://wiki.termux.com/wiki/Termux-usb -*/ - -#include <stdio.h> -#include <assert.h> -#include <libusb-1.0/libusb.h> - -int main(int argc, char **argv) { - libusb_context *context; - libusb_device_handle *handle; - libusb_device *device; - struct libusb_device_descriptor desc; - unsigned char buffer[256]; - int fd; - assert((argc > 1) && (sscanf(argv[1], "%d", &fd) == 1)); - assert(!libusb_init(&context)); - assert(!libusb_wrap_sys_device(context, (intptr_t) fd, &handle)); - device = libusb_get_device(handle); - assert(!libusb_get_device_descriptor(device, &desc)); - printf("vendorid: %04x\n", desc.idVendor); - printf("productid: %04x\n", desc.idProduct); - assert(libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, buffer, 256) >= 0); - printf("manufacturer: %s\n", buffer); - assert(libusb_get_string_descriptor_ascii(handle, desc.iProduct, buffer, 256) >= 0); - printf("product: %s\n", buffer); - // assert(libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, buffer, 256) >= 0); - // printf("Serial No: %s\n", buffer); - libusb_exit(context); -} diff --git a/tests/imports.sh b/tests/imports.sh index f14b6bde..3d810b57 100644 --- a/tests/imports.sh +++ b/tests/imports.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash - _paths() { + pwd # shellcheck disable=SC2156 - find . \( -name .git -prune \) -o \( -name modules -prune \) -o \( -name rust -prune \) -o \( -name target -prune \) -o -name '*' -type f \ + find . \( -name .git -prune \) -o \( -name modules -prune \) -o \( -name node_modules -prune \) -o \( -name rust -prune \) -o \( -name target -prune \) -o -name '*' -type f \ -exec bash -c "grep -o '[^ =:]*DOTFILES[^ ]*' {}" \; \ | grep -o '[^ =:]*DOTFILES[^ ]*' \ | grep -Ev '=|local' \ diff --git a/tests/references.sh b/tests/references.sh index 2812b9e2..76af9ff3 100644 --- a/tests/references.sh +++ b/tests/references.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash - _files() { find . \ \( -name .git -prune \) \ @@ -13,6 +12,7 @@ _files() { | grep -v 'completions' \ | grep -v 'references' \ | grep -v 'bin/dot' \ + | grep -v 'node_modules' \ | grep -v 'STORE' \ | grep -v 'help.sh' }