diff --git a/colorschemes/_theme.py b/colorschemes/_theme.py
index a467d1e..644f440 100644
--- a/colorschemes/_theme.py
+++ b/colorschemes/_theme.py
@@ -4,22 +4,22 @@
base16_name = "eighties"
name = "base16-" + base16_name
base16_colors = [
- "#2d2d2d", # 0
- "#393939", # 1
- "#515151", # 2
- "#747369", # 3
- "#a09f93", # 4
- "#d3d0c8", # 5
- "#e8e6df", # 6
- "#f2f0ec", # 7
- "#f2777a", # 8
- "#f99157", # 9
- "#ffcc66", # a
- "#99cc99", # b
- "#66cccc", # c
- "#6699cc", # d
- "#cc99cc", # e
- "#d27b53", # f
+ "#2d2d2d", # 0
+ "#393939", # 1
+ "#515151", # 2
+ "#747369", # 3
+ "#a09f93", # 4
+ "#d3d0c8", # 5
+ "#e8e6df", # 6
+ "#f2f0ec", # 7
+ "#f2777a", # 8
+ "#f99157", # 9
+ "#ffcc66", # a
+ "#99cc99", # b
+ "#66cccc", # c
+ "#6699cc", # d
+ "#cc99cc", # e
+ "#d27b53", # f
]
bg = base16_colors[0x0]
@@ -32,19 +32,18 @@ selection_bg = base16_colors[0x2]
selection_fg = fg
ansi_colors = [
- base16_colors[int(i, 16)]
- for i in "0 8 B A D E C 5 3 8 B A D E C 7 9 F 1 2 4 6".split()
+ base16_colors[int(i, 16)] for i in "0 8 B A D E C 5 3 8 B A D E C 7 9 F 1 2 4 6".split()
]
link_color = ansi_colors[0xC]
css_variables_prefix = "dotfiles-colorscheme-"
css_variables = {
- "bg": bg,
- "fg": fg,
- "selection-bg": selection_bg,
- "selection-fg": selection_fg,
- "cursor-bg": cursor_bg,
- "cursor-fg": cursor_fg,
- **{"base-{:02X}".format(index): color for index, color in enumerate(base16_colors)},
+ "bg": bg,
+ "fg": fg,
+ "selection-bg": selection_bg,
+ "selection-fg": selection_fg,
+ "cursor-bg": cursor_bg,
+ "cursor-fg": cursor_fg,
+ **{"base-{:02X}".format(index): color for index, color in enumerate(base16_colors)},
}
diff --git a/colorschemes/iterm.itermcolors.py b/colorschemes/iterm.itermcolors.py
index 5594ff5..8cd59e5 100755
--- a/colorschemes/iterm.itermcolors.py
+++ b/colorschemes/iterm.itermcolors.py
@@ -2,8 +2,9 @@
import _theme as theme
+
print(
- """\
+ """\
@@ -13,9 +14,9 @@ print(
def print_color(key_name, color):
- r, g, b = [float(int(color[2 * i + 1 : 2 * i + 3], 16)) / 255 for i in range(3)]
- print(
- """\
+ r, g, b = [float(int(color[2 * i + 1:2 * i + 3], 16)) / 255 for i in range(3)]
+ print(
+ """\
{} Color
Color Space
@@ -27,10 +28,8 @@ def print_color(key_name, color):
Blue Component
{}
\
-""".format(
- key_name, r, g, b
- )
- )
+""".format(key_name, r, g, b)
+ )
print_color("Background", theme.bg)
@@ -41,12 +40,10 @@ print_color("Cursor Text", theme.cursor_fg)
print_color("Selection Color", theme.selection_bg)
print_color("Selected Text Color", theme.selection_fg)
for index, color in enumerate(theme.ansi_colors[:16]):
- print_color("Ansi " + str(index), color)
+ print_color("Ansi " + str(index), color)
print_color("Link", theme.link_color)
-print(
- """\
+print("""\
\
-"""
-)
+""")
diff --git a/colorschemes/kitty.conf.py b/colorschemes/kitty.conf.py
index a82df90..81544aa 100755
--- a/colorschemes/kitty.conf.py
+++ b/colorschemes/kitty.conf.py
@@ -4,7 +4,7 @@ import _theme as theme
def print_color(key_name, color):
- print("{} {}".format(key_name, color))
+ print("{} {}".format(key_name, color))
print_color("background", theme.bg)
@@ -14,7 +14,7 @@ print_color("cursor_text_color", theme.cursor_fg)
print_color("selection_background", theme.selection_bg)
print_color("selection_foreground", theme.selection_fg)
for index, color in enumerate(theme.ansi_colors[:16]):
- print_color("color" + str(index), color)
+ print_color("color" + str(index), color)
print_color("url_color", theme.link_color)
print_color("active_border_color", theme.ansi_colors[2])
diff --git a/colorschemes/prismjs-theme.css.py b/colorschemes/prismjs-theme.css.py
index 42b62b8..924f81d 100755
--- a/colorschemes/prismjs-theme.css.py
+++ b/colorschemes/prismjs-theme.css.py
@@ -4,11 +4,9 @@ import _theme as theme
import os
with open(os.path.join(os.path.dirname(__file__), "prismjs-theme-src.css")) as f:
- css_src = f.read()
+ css_src = f.read()
for var_name, color in theme.css_variables.items():
- css_src = css_src.replace(
- "var(--{}{})".format(theme.css_variables_prefix, var_name), color
- )
+ css_src = css_src.replace("var(--{}{})".format(theme.css_variables_prefix, var_name), color)
print(css_src)
diff --git a/colorschemes/setvtrgb.txt.py b/colorschemes/setvtrgb.txt.py
index 8a8f117..9dfb27f 100755
--- a/colorschemes/setvtrgb.txt.py
+++ b/colorschemes/setvtrgb.txt.py
@@ -8,11 +8,4 @@ import _theme as theme
# 0,0,0,0,170,170,170,170,85,85,85,85,255,255,255,255
for i in range(3):
- print(
- ",".join(
- [
- str(int(color[2 * i + 1 : 2 * i + 3], 16))
- for color in theme.ansi_colors[:16]
- ]
- )
- )
+ print(",".join([str(int(color[2 * i + 1:2 * i + 3], 16)) for color in theme.ansi_colors[:16]]))
diff --git a/colorschemes/termux.properties.py b/colorschemes/termux.properties.py
index 164df7a..e6843ff 100755
--- a/colorschemes/termux.properties.py
+++ b/colorschemes/termux.properties.py
@@ -4,11 +4,11 @@ import _theme as theme
def print_color(key_name, color):
- print("{}={}".format(key_name, color))
+ print("{}={}".format(key_name, color))
print_color("background", theme.bg)
print_color("foreground", theme.fg)
print_color("cursor", theme.cursor_bg)
for index, color in enumerate(theme.ansi_colors[:16]):
- print_color("color" + str(index), color)
+ print_color("color" + str(index), color)
diff --git a/colorschemes/variables.css.py b/colorschemes/variables.css.py
index 64c4609..2338a6f 100755
--- a/colorschemes/variables.css.py
+++ b/colorschemes/variables.css.py
@@ -2,7 +2,8 @@
import _theme as theme
+
print(":root {")
for var_name, color in theme.css_variables.items():
- print(" --{}{}: {};".format(theme.css_variables_prefix, var_name, color))
+ print(" --{}{}: {};".format(theme.css_variables_prefix, var_name, color))
print("}")
diff --git a/colorschemes/vim.vim.py b/colorschemes/vim.vim.py
index bba2493..38dfed0 100755
--- a/colorschemes/vim.vim.py
+++ b/colorschemes/vim.vim.py
@@ -2,20 +2,21 @@
import _theme as theme
+
print("let dotfiles_colorscheme_name = '{}'".format(theme.name))
print("let dotfiles_colorscheme_base16_name = '{}'".format(theme.base16_name))
print("let dotfiles_colorscheme_base16_colors = [")
gui_to_cterm_mapping = [0, 18, 19, 8, 20, 7, 21, 15, 1, 16, 3, 2, 6, 4, 5, 17]
for colors_pair in zip(theme.base16_colors[:16], gui_to_cterm_mapping):
- print("\\ {{'gui': '{}', 'cterm': '{:>02}'}},".format(*colors_pair))
+ print("\\ {{'gui': '{}', 'cterm': '{:>02}'}},".format(*colors_pair))
print("\\ ]")
def print_terminal_color(key_name, color):
- print("let terminal_color_{} = '{}'".format(key_name, color))
+ print("let terminal_color_{} = '{}'".format(key_name, color))
print_terminal_color("background", theme.bg)
print_terminal_color("foreground", theme.fg)
for index, color in enumerate(theme.ansi_colors[:16]):
- print_terminal_color(str(index), color)
+ print_terminal_color(str(index), color)
diff --git a/colorschemes/vscode-colorCustomizations.json.py b/colorschemes/vscode-colorCustomizations.json.py
index d139834..ed1b1dc 100755
--- a/colorschemes/vscode-colorCustomizations.json.py
+++ b/colorschemes/vscode-colorCustomizations.json.py
@@ -5,31 +5,27 @@ import json
ANSI_COLOR_NAMES = [
- "Black",
- "Red",
- "Green",
- "Yellow",
- "Blue",
- "Magenta",
- "Cyan",
- "White",
+ "Black",
+ "Red",
+ "Green",
+ "Yellow",
+ "Blue",
+ "Magenta",
+ "Cyan",
+ "White",
]
colors = {
- "terminal.background": theme.bg,
- "terminal.foreground": theme.fg,
- "terminal.selectionBackground": theme.selection_bg,
- "terminalCursor.background": theme.cursor_fg,
- "terminalCursor.foreground": theme.cursor_bg,
+ "terminal.background": theme.bg,
+ "terminal.foreground": theme.fg,
+ "terminal.selectionBackground": theme.selection_bg,
+ "terminalCursor.background": theme.cursor_fg,
+ "terminalCursor.foreground": theme.cursor_bg,
}
for color_brightness in [False, True]:
- for color_index, color_name in enumerate(ANSI_COLOR_NAMES):
- color = theme.ansi_colors[
- color_index + int(color_brightness) * len(ANSI_COLOR_NAMES)
- ]
- colors[
- "terminal.ansi" + ("Bright" if color_brightness else "") + color_name
- ] = color
+ for color_index, color_name in enumerate(ANSI_COLOR_NAMES):
+ color = theme.ansi_colors[color_index + int(color_brightness) * len(ANSI_COLOR_NAMES)]
+ colors["terminal.ansi" + ("Bright" if color_brightness else "") + color_name] = color
print(json.dumps(colors, ensure_ascii=False, indent=2))
diff --git a/colorschemes/xfce4-terminal.theme.py b/colorschemes/xfce4-terminal.theme.py
index 5775160..3b5f71e 100755
--- a/colorschemes/xfce4-terminal.theme.py
+++ b/colorschemes/xfce4-terminal.theme.py
@@ -2,6 +2,7 @@
import _theme as theme
+
print("[Scheme]")
print("Name=dmitmel's dotfiles colorscheme")
print("ColorForeground={}".format(theme.fg))
diff --git a/colorschemes/zsh.zsh.py b/colorschemes/zsh.zsh.py
index 96c73af..5a32295 100755
--- a/colorschemes/zsh.zsh.py
+++ b/colorschemes/zsh.zsh.py
@@ -2,19 +2,18 @@
import _theme as theme
-
for attr in [
- "bg",
- "fg",
- "cursor_bg",
- "cursor_fg",
- "selection_bg",
- "selection_fg",
- "link_color",
+ "bg",
+ "fg",
+ "cursor_bg",
+ "cursor_fg",
+ "selection_bg",
+ "selection_fg",
+ "link_color",
]:
- color = getattr(theme, attr)
- print("colorscheme_{}={}".format(attr, color[1:]))
+ color = getattr(theme, attr)
+ print("colorscheme_{}={}".format(attr, color[1:]))
print("colorscheme_ansi_colors=(")
for color in theme.ansi_colors:
- print(" {}".format(color[1:]))
+ print(" {}".format(color[1:]))
print(")")
diff --git a/nvim/after/ftplugin/fugitive.vim b/nvim/after/ftplugin/fugitive.vim
new file mode 100644
index 0000000..ab49c88
--- /dev/null
+++ b/nvim/after/ftplugin/fugitive.vim
@@ -0,0 +1 @@
+setlocal nofoldenable foldmethod=manual
diff --git a/nvim/after/ftplugin/haskell.vim b/nvim/after/ftplugin/haskell.vim
index bdabaed..8d98c34 100644
--- a/nvim/after/ftplugin/haskell.vim
+++ b/nvim/after/ftplugin/haskell.vim
@@ -1,3 +1 @@
-let g:haskall_test = 1
-setlocal foldmethod<
-setlocal foldtext<
+setlocal foldmethod< foldtext<
diff --git a/nvim/after/syntax/cabal.vim b/nvim/after/syntax/cabal.vim
index 8ced55f..8d98c34 100644
--- a/nvim/after/syntax/cabal.vim
+++ b/nvim/after/syntax/cabal.vim
@@ -1,2 +1 @@
-setlocal foldmethod<
-setlocal foldtext<
+setlocal foldmethod< foldtext<
diff --git a/nvim/after/syntax/cabalconfig.vim b/nvim/after/syntax/cabalconfig.vim
index 8ced55f..8d98c34 100644
--- a/nvim/after/syntax/cabalconfig.vim
+++ b/nvim/after/syntax/cabalconfig.vim
@@ -1,2 +1 @@
-setlocal foldmethod<
-setlocal foldtext<
+setlocal foldmethod< foldtext<
diff --git a/nvim/after/syntax/nginx.vim b/nvim/after/syntax/nginx.vim
index 1e4e3af..bf72a83 100644
--- a/nvim/after/syntax/nginx.vim
+++ b/nvim/after/syntax/nginx.vim
@@ -4,5 +4,4 @@
" sourced in `syntax/nginx.vim` in vim-polyglot, which resets the `commentstring`
" set in `ftplugin/nginx.vim` and sets `comments` to some garbage. This script
" undoes that damage.
-setlocal comments<
-setlocal commentstring=#%s
+setlocal comments< commentstring=#%s
diff --git a/nvim/coc-languages/python.vim b/nvim/coc-languages/python.vim
index ff6cd12..20b80e1 100644
--- a/nvim/coc-languages/python.vim
+++ b/nvim/coc-languages/python.vim
@@ -1,12 +1,15 @@
let g:coc_global_extensions += ['coc-pyright']
let g:coc_filetypes += ['python']
-" let g:coc_user_config['pyls.plugins.pycodestyle.ignore'] = ['E501']
+
" let g:coc_user_config['python.autocomplete.showAdvancedMembers'] = v:false
let g:coc_user_config['python'] = {
-\ 'formatting': { 'provider': 'black' },
+\ 'formatting': {
+\ 'provider': 'yapf',
+\ 'yapfArgs': ['--style=' . simplify(g:nvim_dotfiles_dir.'/../python/yapf.ini')]
+\ },
\ 'linting': {
\ 'pylintEnabled': v:false,
\ 'flake8Enabled': v:true,
-\ 'flake8Args': ['--ignore', 'E501'],
+\ 'flake8Args': ['--config=' . simplify(g:nvim_dotfiles_dir.'/../python/flake8.ini')],
\ },
\ }
diff --git a/nvim/dotfiles/plugins-list.vim b/nvim/dotfiles/plugins-list.vim
index e64ce85..ccd39a0 100644
--- a/nvim/dotfiles/plugins-list.vim
+++ b/nvim/dotfiles/plugins-list.vim
@@ -16,6 +16,7 @@
Plug 'tpope/vim-repeat'
" if g:vim_ide
Plug 'tomtom/tcomment_vim'
+ Plug 'glts/vim-textobj-comment'
" else
" Plug 'tpope/vim-commentary'
" endif
@@ -44,9 +45,6 @@
Plug 'vim-airline/vim-airline'
Plug 'tpope/vim-obsession'
Plug 'romainl/vim-qf'
- if g:vim_ide
- Plug 'dyng/ctrlsf.vim'
- endif
" }}}
" Git {{{
diff --git a/nvim/plugin/editing.vim b/nvim/plugin/editing.vim
index d53d96a..46cbe9b 100644
--- a/nvim/plugin/editing.vim
+++ b/nvim/plugin/editing.vim
@@ -58,23 +58,17 @@ set commentstring=//%s
" Cursor and Scrolling {{{
-
- set number
- set relativenumber
- set cursorline
-
+ set number relativenumber cursorline
" remember cursor position
augroup vimrc-editing-remember-cursor-position
autocmd!
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exec "normal! g`\"" | endif
augroup END
-
" }}}
" Wrapping {{{
- set nowrap
- set colorcolumn=81,101,121
+ set nowrap colorcolumn=81,101,121
" }}}
@@ -236,6 +230,7 @@ set commentstring=//%s
" Remove the mappings that I won't use
let g:tcomment_maps = 0
+ " Closely replicate the behavior of tpope/vim-commentary
nmap gc TComment_gc
nmap gcc TComment_gcc
nmap gC TComment_gcb
@@ -244,6 +239,8 @@ set commentstring=//%s
nmap gCC m'o''TComment_gcb+
xnoremap gc :TCommentMaybeInline
xnoremap gC :TCommentBlock
+ " Make an alias for the comment text object
+ omap gc ac
" }}}
diff --git a/nvim/plugin/files.vim b/nvim/plugin/files.vim
index 14fa58f..da700db 100644
--- a/nvim/plugin/files.vim
+++ b/nvim/plugin/files.vim
@@ -20,6 +20,23 @@ nnoremap empty(&buftype) ? ":writewall\" : "\"
command! -bang -nargs=* Rg call fzf#vim#grep(s:rg_cmd . ' --column --line-number --no-heading --fixed-strings --smart-case --color always ' . shellescape(), 1, 0)
command! -bang -nargs=* Find Rg
endif
+
+ nnoremap / :grep
+
+ function! s:grep_mapping_star_normal()
+ let word = expand("")
+ if !empty(word)
+ call feedkeys(":\grep " . shellescape('\b' . word . '\b'), 'n')
+ endif
+ endfunction
+ function! s:grep_mapping_star_visual()
+ let tmp = @"
+ normal! y
+ call feedkeys(":\grep " . shellescape(@"), 'n')
+ let @" = tmp
+ endfunction
+ nnoremap * call grep_mapping_star_normal()
+ xnoremap * call grep_mapping_star_visual()
" }}}
@@ -29,7 +46,10 @@ nnoremap empty(&buftype) ? ":writewall\" : "\"
let g:loaded_netrwPlugin = 1
" re-add Netrw's gx mappings since we've disabled them
nnoremap gx call netrw#BrowseX(expand(''),netrw#CheckIfRemote())
- xnoremap gx call netrw#BrowseXVis()
+ " This one can be rewritten in a way to not clobber the yank register...
+ " Most notably, the built-in mapping, which uses netrw#BrowseXVis(), doesn't
+ " work and breaks the editor, at least for me.
+ xnoremap gx y:call netrw#BrowseX(@",netrw#CheckIfRemote())
" }}}
@@ -176,10 +196,3 @@ nnoremap empty(&buftype) ? ":writewall\" : "\"
augroup END
" }}}
-
-
-" CtrlSF {{{
- nmap / CtrlSFPrompt
- nmap * CtrlSFCwordPath
- xmap * CtrlSFVwordPath
-" }}}
diff --git a/python/flake8.ini b/python/flake8.ini
new file mode 100644
index 0000000..b0c0191
--- /dev/null
+++ b/python/flake8.ini
@@ -0,0 +1,12 @@
+[flake8]
+ignore =
+ # Indent is not a multiple of 4
+ E111
+ # Indent is not a multiple of 4 for comments
+ E114
+ # Indent for continuation lines is smaller than expected
+ E121
+ # Import not at the top of the file
+ E402
+ # Line too long
+ E501
diff --git a/python/yapf.ini b/python/yapf.ini
new file mode 100644
index 0000000..e4ceea7
--- /dev/null
+++ b/python/yapf.ini
@@ -0,0 +1,9 @@
+[style]
+based_on_style = google
+column_limit = 99
+indent_width = 2
+continuation_indent_width = 2
+blank_lines_between_top_level_imports_and_variables = 2
+dedent_closing_brackets = true
+coalesce_brackets = true
+spaces_around_power_operator = true
diff --git a/script-resources/common_script_utils.py b/script-resources/common_script_utils.py
index fa23b02..239eb11 100644
--- a/script-resources/common_script_utils.py
+++ b/script-resources/common_script_utils.py
@@ -4,95 +4,90 @@ import subprocess
from pathlib import Path
from typing import Iterable, NoReturn
-
if os.name == "posix":
- DOTFILES_CONFIG_DIR: Path = Path.home() / ".config" / "dotfiles"
- DOTFILES_CACHE_DIR: Path = Path.home() / ".cache" / "dotfiles"
+ DOTFILES_CONFIG_DIR: Path = Path.home() / ".config" / "dotfiles"
+ DOTFILES_CACHE_DIR: Path = Path.home() / ".cache" / "dotfiles"
def platform_not_supported_error() -> NoReturn:
- raise Exception("platform '{}' is not supported!".format(sys.platform))
+ raise Exception("platform '{}' is not supported!".format(sys.platform))
-def run_chooser(
- choices: Iterable[str], prompt: str = None, async_read: bool = False
-) -> int:
- supports_result_index = True
- if os.isatty(sys.stderr.fileno()):
- process_args = [
- "fzf",
- "--with-nth=2..",
- "--height=50%",
- "--reverse",
- "--tiebreak=index",
- ]
- supports_result_index = False
- elif sys.platform == "darwin":
- process_args = ["choose", "-i"]
- elif os.name == "posix":
- process_args = ["rofi", "-dmenu", "-i", "-format", "i"]
- if prompt is not None:
- process_args += ["-p", prompt]
- if async_read:
- process_args += ["-async-pre-read", "0"]
- else:
- platform_not_supported_error()
+def run_chooser(choices: Iterable[str], prompt: str = None, async_read: bool = False) -> int:
+ supports_result_index = True
+ if os.isatty(sys.stderr.fileno()):
+ process_args = [
+ "fzf",
+ "--with-nth=2..",
+ "--height=50%",
+ "--reverse",
+ "--tiebreak=index",
+ ]
+ supports_result_index = False
+ elif sys.platform == "darwin":
+ process_args = ["choose", "-i"]
+ elif os.name == "posix":
+ process_args = ["rofi", "-dmenu", "-i", "-format", "i"]
+ if prompt is not None:
+ process_args += ["-p", prompt]
+ if async_read:
+ process_args += ["-async-pre-read", "0"]
+ else:
+ platform_not_supported_error()
- chooser_process = subprocess.Popen(
- process_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE
- )
+ chooser_process = subprocess.Popen(process_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- with chooser_process.stdin as pipe:
- for index, choice in enumerate(choices):
- assert "\n" not in choice
- if not supports_result_index:
- pipe.write(str(index).encode())
- pipe.write(b" ")
- pipe.write(choice.encode())
- pipe.write(b"\n")
+ with chooser_process.stdin as pipe:
+ for index, choice in enumerate(choices):
+ assert "\n" not in choice
+ if not supports_result_index:
+ pipe.write(str(index).encode())
+ pipe.write(b" ")
+ pipe.write(choice.encode())
+ pipe.write(b"\n")
- exit_code: int = chooser_process.wait()
- if exit_code != 0:
- raise Exception("chooser process failed with exit code {}".format(exit_code))
+ exit_code: int = chooser_process.wait()
+ if exit_code != 0:
+ raise Exception("chooser process failed with exit code {}".format(exit_code))
- chosen_index = int(chooser_process.stdout.read().strip().split()[0])
- return chosen_index
+ chosen_index = int(chooser_process.stdout.read().strip().split()[0])
+ return chosen_index
def send_notification(title: str, message: str, url: str = None) -> None:
- if sys.platform == "darwin":
- process_args = [
- "terminal-notifier",
- "-title",
- title,
- "-message",
- message,
- "-open",
- ]
- if url is not None:
- process_args += [url]
- elif os.name == "posix":
- process_args = [
- "notify-send",
- "--icon=utilities-terminal",
- "--expire-time=3000",
- title,
- message,
- ]
- else:
- platform_not_supported_error()
+ if sys.platform == "darwin":
+ process_args = [
+ "terminal-notifier",
+ "-title",
+ title,
+ "-message",
+ message,
+ "-open",
+ ]
+ if url is not None:
+ process_args += [url]
+ elif os.name == "posix":
+ process_args = [
+ "notify-send",
+ "--icon=utilities-terminal",
+ "--expire-time=3000",
+ title,
+ message,
+ ]
+ else:
+ platform_not_supported_error()
- subprocess.run(process_args, check=True)
+ subprocess.run(process_args, check=True)
def set_clipboard(text: str) -> None:
- # TODO: somehow merge program selection with the logic in `zsh/functions.zsh`
- if sys.platform == "darwin":
- process_args = ["pbcopy"]
- elif os.name == "posix":
- process_args = ["xsel", "--clipboard", "--input"]
- # process_args = ["xclip", "-in", "-selection", "clipboard"]
- else:
- platform_not_supported_error()
+ # TODO: somehow merge program selection with the logic in `zsh/functions.zsh`
+ if sys.platform == "darwin":
+ process_args = ["pbcopy"]
+ elif os.name == "posix":
+ process_args = ["xsel", "--clipboard", "--input"]
+ # process_args = ["xclip", "-in", "-selection", "clipboard"]
+ else:
+ platform_not_supported_error()
- subprocess.run(process_args, input=text.encode(), check=True)
+ subprocess.run(process_args, input=text.encode(), check=True)
diff --git a/script-resources/factorio/property_tree.py b/script-resources/factorio/property_tree.py
index 9275ff4..24f921c 100644
--- a/script-resources/factorio/property_tree.py
+++ b/script-resources/factorio/property_tree.py
@@ -9,58 +9,58 @@ from typing import Any, IO
def read_bool(buf: IO[bytes]) -> bool:
- return buf.read(1)[0] == 1
+ return buf.read(1)[0] == 1
def read_number(buf: IO[bytes]) -> float:
- return struct.unpack(" int:
- return struct.unpack(" str:
- is_empty = read_bool(buf)
- if is_empty:
- return ""
- len_ = buf.read(1)[0]
- if len_ == 0xFF:
- len_ = _read_length(buf)
- return buf.read(len_).decode("utf8")
+ is_empty = read_bool(buf)
+ if is_empty:
+ return ""
+ len_ = buf.read(1)[0]
+ if len_ == 0xFF:
+ len_ = _read_length(buf)
+ return buf.read(len_).decode("utf8")
def read_dictionary(buf: IO[bytes]) -> dict[str, Any]:
- len_ = _read_length(buf)
- value: dict[str, Any] = {}
- for _ in range(len_):
- key = read_string(buf)
- value[key] = read(buf)
- return value
+ len_ = _read_length(buf)
+ value: dict[str, Any] = {}
+ for _ in range(len_):
+ key = read_string(buf)
+ value[key] = read(buf)
+ return value
def read_list(buf: IO[bytes]) -> list[Any]:
- len_ = _read_length(buf)
- value: list[Any] = []
- for _ in range(len_):
- read_string(buf)
- value.append(read(buf))
- return value
+ len_ = _read_length(buf)
+ value: list[Any] = []
+ for _ in range(len_):
+ read_string(buf)
+ value.append(read(buf))
+ return value
def read(buf: IO[bytes]) -> Any:
- type_, _any_type_flag = buf.read(2)
- if type_ == 0:
- return None
- elif type_ == 1:
- return read_bool(buf)
- elif type_ == 2:
- return read_number(buf)
- elif type_ == 3:
- return read_string(buf)
- elif type_ == 4:
- return read_list(buf)
- elif type_ == 5:
- return read_dictionary(buf)
- else:
- raise Exception("unknown property tree type 0x{:02x}".format(type_))
+ type_, _any_type_flag = buf.read(2)
+ if type_ == 0:
+ return None
+ elif type_ == 1:
+ return read_bool(buf)
+ elif type_ == 2:
+ return read_number(buf)
+ elif type_ == 3:
+ return read_string(buf)
+ elif type_ == 4:
+ return read_list(buf)
+ elif type_ == 5:
+ return read_dictionary(buf)
+ else:
+ raise Exception("unknown property tree type 0x{:02x}".format(type_))
diff --git a/script-resources/pycalc_startup.py b/script-resources/pycalc_startup.py
index 6aab338..1ffb1b2 100644
--- a/script-resources/pycalc_startup.py
+++ b/script-resources/pycalc_startup.py
@@ -3,29 +3,29 @@ from fractions import Fraction
def factors(n):
- result = set()
- for i in range(1, int(sqrt(n)) + 1):
- if n % i == 0:
- result.add(i)
- result.add(n // i)
- return result
+ result = set()
+ for i in range(1, int(sqrt(n)) + 1):
+ if n % i == 0:
+ result.add(i)
+ result.add(n // i)
+ return result
def solve_quadratic(a, b, c):
- if a == 0:
- raise Exception("not a quadratic equation")
+ if a == 0:
+ raise Exception("not a quadratic equation")
+ else:
+ d = b ** 2 - 4 * a * c
+ print("D = " + str(d))
+ if d < 0:
+ print("no solutions")
+ elif d > 0:
+ sd = sqrt(d)
+ print("sqrt(D) = " + str(sd))
+ print("x1 = " + str((-b + sd) / (2 * a)))
+ print("x2 = " + str((-b - sd) / (2 * a)))
else:
- d = b ** 2 - 4 * a * c
- print("D = " + str(d))
- if d < 0:
- print("no solutions")
- elif d > 0:
- sd = sqrt(d)
- print("sqrt(D) = " + str(sd))
- print("x1 = " + str((-b + sd) / (2 * a)))
- print("x2 = " + str((-b - sd) / (2 * a)))
- else:
- print("x = " + str(-b / (2 * a)))
+ print("x = " + str(-b / (2 * a)))
print("loaded Python calculator")
diff --git a/script-resources/welcome/colors.py b/script-resources/welcome/colors.py
index b32d782..a835612 100644
--- a/script-resources/welcome/colors.py
+++ b/script-resources/welcome/colors.py
@@ -1,21 +1,22 @@
from colorama import Fore, Style, ansi
+
COLORS = [ansi.code_to_chars(30 + color_index) for color_index in range(0, 8)]
def colored(string, *colors):
- return "".join(colors + (string, Style.RESET_ALL))
+ return "".join(colors + (string, Style.RESET_ALL))
def bright_colored(string, *colors):
- return "".join(colors + (Style.BRIGHT, string, Style.RESET_ALL))
+ return "".join(colors + (Style.BRIGHT, string, Style.RESET_ALL))
def colorize_percent(percent, warning, critical, inverse=False):
- COLORS = [Fore.GREEN, Fore.YELLOW, Fore.RED]
+ COLORS = [Fore.GREEN, Fore.YELLOW, Fore.RED]
- color_index = 0 if percent < warning else 1 if percent < critical else 2
- if inverse:
- color_index = 2 - color_index
+ color_index = 0 if percent < warning else 1 if percent < critical else 2
+ if inverse:
+ color_index = 2 - color_index
- return colored("%.2f%%" % percent, COLORS[color_index])
+ return colored("%.2f%%" % percent, COLORS[color_index])
diff --git a/script-resources/welcome/humanize.py b/script-resources/welcome/humanize.py
index ac7c7fb..9631a9c 100644
--- a/script-resources/welcome/humanize.py
+++ b/script-resources/welcome/humanize.py
@@ -1,34 +1,34 @@
def humanize_timedelta(timedelta):
- result = []
+ result = []
- days = timedelta.days
- mm, ss = divmod(timedelta.seconds, 60)
- hh, mm = divmod(mm, 60)
+ days = timedelta.days
+ mm, ss = divmod(timedelta.seconds, 60)
+ hh, mm = divmod(mm, 60)
- def plural(n):
- return n, "s" if abs(n) != 1 else ""
+ def plural(n):
+ return n, "s" if abs(n) != 1 else ""
- if days > 0:
- result.append("%d day%s" % plural(days))
- if hh > 0 or result:
- result.append("%d hour%s" % plural(hh))
- if mm > 0 or result:
- result.append("%d min%s" % plural(mm))
- if len(result) <= 1:
- result.append("%d sec%s" % plural(ss))
+ if days > 0:
+ result.append("%d day%s" % plural(days))
+ if hh > 0 or result:
+ result.append("%d hour%s" % plural(hh))
+ if mm > 0 or result:
+ result.append("%d min%s" % plural(mm))
+ if len(result) <= 1:
+ result.append("%d sec%s" % plural(ss))
- return ", ".join(result)
+ return ", ".join(result)
def humanize_bytes(bytes):
- units = ["B", "kB", "MB", "GB"]
+ units = ["B", "kB", "MB", "GB"]
- factor = 1
- unit = ""
- for unit in units:
- next_factor = factor << 10
- if bytes < next_factor:
- break
- factor = next_factor
+ factor = 1
+ unit = ""
+ for unit in units:
+ next_factor = factor << 10
+ if bytes < next_factor:
+ break
+ factor = next_factor
- return "%.2f %s" % (float(bytes) / factor, unit)
+ return "%.2f %s" % (float(bytes) / factor, unit)
diff --git a/script-resources/welcome/main.py b/script-resources/welcome/main.py
index 40e9c42..6eb37f7 100755
--- a/script-resources/welcome/main.py
+++ b/script-resources/welcome/main.py
@@ -5,6 +5,7 @@ import re
from colors import COLORS, Style
from system_info import get_system_info
+
print("")
logo_lines, info_lines = get_system_info()
@@ -12,24 +13,24 @@ logo_line_widths = [len(re.sub(r"{\d}", "", line)) for line in logo_lines]
logo_width = max(logo_line_widths)
for line_index in range(0, max(len(logo_lines), len(info_lines))):
- line = ""
+ line = ""
- logo_line_width = 0
+ logo_line_width = 0
- if line_index < len(logo_lines):
- logo_line = logo_lines[line_index]
- logo_line_width = logo_line_widths[line_index]
+ if line_index < len(logo_lines):
+ logo_line = logo_lines[line_index]
+ logo_line_width = logo_line_widths[line_index]
- line += Style.BRIGHT
- line += logo_line.format(*COLORS)
- line += Style.RESET_ALL
+ line += Style.BRIGHT
+ line += logo_line.format(*COLORS)
+ line += Style.RESET_ALL
- line += " " * (logo_width - logo_line_width + 3)
+ line += " " * (logo_width - logo_line_width + 3)
- if line_index < len(info_lines):
- info_line = info_lines[line_index]
- line += info_line
+ if line_index < len(info_lines):
+ info_line = info_lines[line_index]
+ line += info_line
- print(line)
+ print(line)
print("")
diff --git a/script-resources/welcome/system_info.py b/script-resources/welcome/system_info.py
index d840055..9d72ded 100644
--- a/script-resources/welcome/system_info.py
+++ b/script-resources/welcome/system_info.py
@@ -11,206 +11,200 @@ from humanize import humanize_bytes, humanize_timedelta
def get_system_info():
- info_lines = []
+ info_lines = []
- def info(name, value, *format_args):
- line = bright_colored(name + ":", Fore.YELLOW) + " " + value
- if format_args:
- line = line % format_args
- info_lines.append(line)
+ def info(name, value, *format_args):
+ line = bright_colored(name + ":", Fore.YELLOW) + " " + value
+ if format_args:
+ line = line % format_args
+ info_lines.append(line)
- username = getuser()
- hostname = _get_hostname()
+ username = getuser()
+ hostname = _get_hostname()
- info_lines.append(
- bright_colored(username, Fore.BLUE) + "@" + bright_colored(hostname, Fore.RED)
- )
- info_lines.append("")
+ info_lines.append(bright_colored(username, Fore.BLUE) + "@" + bright_colored(hostname, Fore.RED))
+ info_lines.append("")
- distro_id, distro_name, distro_version, distro_codename = _get_distro_info()
- info("OS", " ".join([distro_name, distro_version, distro_codename]))
+ distro_id, distro_name, distro_version, distro_codename = _get_distro_info()
+ info("OS", " ".join([distro_name, distro_version, distro_codename]))
- logo_path = os.path.join(os.path.dirname(__file__), "logos", distro_id)
- with open(logo_path) as logo_file:
- logo_lines = logo_file.read().splitlines()
+ logo_path = os.path.join(os.path.dirname(__file__), "logos", distro_id)
+ with open(logo_path) as logo_file:
+ logo_lines = logo_file.read().splitlines()
- info("Kernel", "%s %s", platform.system(), platform.release())
+ info("Kernel", "%s %s", platform.system(), platform.release())
- info("Uptime", humanize_timedelta(_get_uptime()))
+ info("Uptime", humanize_timedelta(_get_uptime()))
- users_info = _get_users()
- if users_info:
- info("Users", users_info)
+ users_info = _get_users()
+ if users_info:
+ info("Users", users_info)
- shell = _get_shell()
- if shell is not None:
- info("Shell", shell)
+ shell = _get_shell()
+ if shell is not None:
+ info("Shell", shell)
- info_lines.append("")
+ info_lines.append("")
- cpu_usage_info = _get_cpu_usage()
- if cpu_usage_info is not None:
- info("CPU Usage", "%s", cpu_usage_info)
- info("Memory", "%s / %s (%s)", *_get_memory())
+ cpu_usage_info = _get_cpu_usage()
+ if cpu_usage_info is not None:
+ info("CPU Usage", "%s", cpu_usage_info)
+ info("Memory", "%s / %s (%s)", *_get_memory())
- for disk_info in _get_disks():
- info("Disk (%s)", "%s / %s (%s)", *disk_info)
+ for disk_info in _get_disks():
+ info("Disk (%s)", "%s / %s (%s)", *disk_info)
- battery_info = _get_battery()
- if battery_info is not None:
- info("Battery", "%s (%s)", *battery_info)
+ battery_info = _get_battery()
+ if battery_info is not None:
+ info("Battery", "%s (%s)", *battery_info)
- info_lines.append("")
+ info_lines.append("")
- for local_ip_address in _get_local_ipv4_addresses():
- info("Local IPv4 Address (%s)", "%s", *local_ip_address)
+ for local_ip_address in _get_local_ipv4_addresses():
+ info("Local IPv4 Address (%s)", "%s", *local_ip_address)
- return logo_lines, info_lines
+ return logo_lines, info_lines
def _get_hostname():
- hostname = socket.gethostname()
- return hostname
+ hostname = socket.gethostname()
+ return hostname
def _get_uptime():
- return datetime.now() - datetime.fromtimestamp(psutil.boot_time())
+ return datetime.now() - datetime.fromtimestamp(psutil.boot_time())
def _get_users():
- users = {}
+ users = {}
- for user in psutil.users():
- name = user.name
- terminal = user.terminal
- if name in users:
- users[name].append(terminal)
- else:
- users[name] = [terminal]
+ for user in psutil.users():
+ name = user.name
+ terminal = user.terminal
+ if name in users:
+ users[name].append(terminal)
+ else:
+ users[name] = [terminal]
- result = []
+ result = []
- for name in users:
- terminals = users[name]
+ for name in users:
+ terminals = users[name]
- colored_name = bright_colored(name, Fore.BLUE)
- colored_terminals = [
- colored(str(term), Style.DIM, Fore.WHITE) for term in terminals
- ]
+ colored_name = bright_colored(name, Fore.BLUE)
+ colored_terminals = [colored(str(term), Style.DIM, Fore.WHITE) for term in terminals]
- terminals_str = ", ".join(colored_terminals)
- if len(colored_terminals) > 1:
- terminals_str = "(%s)" % terminals_str
- result.append(colored_name + "@" + terminals_str)
+ terminals_str = ", ".join(colored_terminals)
+ if len(colored_terminals) > 1:
+ terminals_str = "(%s)" % terminals_str
+ result.append(colored_name + "@" + terminals_str)
- return ", ".join(result)
+ return ", ".join(result)
def _get_shell():
- return os.environ.get("SHELL")
+ return os.environ.get("SHELL")
def _get_cpu_usage():
- try:
- percent = psutil.cpu_percent()
- except Exception as e:
- print("Error in _get_cpu_usage:", e)
- return None
+ try:
+ percent = psutil.cpu_percent()
+ except Exception as e:
+ print("Error in _get_cpu_usage:", e)
+ return None
- return colorize_percent(percent, warning=60, critical=80)
+ return colorize_percent(percent, warning=60, critical=80)
def _get_memory():
- memory = psutil.virtual_memory()
- return (
- humanize_bytes(memory.used),
- humanize_bytes(memory.total),
- colorize_percent(memory.percent, warning=60, critical=80),
- )
+ memory = psutil.virtual_memory()
+ return (
+ humanize_bytes(memory.used),
+ humanize_bytes(memory.total),
+ colorize_percent(memory.percent, warning=60, critical=80),
+ )
def _get_disks():
- result = []
+ result = []
- for disk in psutil.disk_partitions(all=False):
- if psutil.WINDOWS and ("cdrom" in disk.opts or disk.fstype == ""):
- # skip cd-rom drives with no disk in it on Windows; they may raise
- # ENOENT, pop-up a Windows GUI error for a non-ready partition or
- # just hang
- continue
+ for disk in psutil.disk_partitions(all=False):
+ if psutil.WINDOWS and ("cdrom" in disk.opts or disk.fstype == ""):
+ # skip cd-rom drives with no disk in it on Windows; they may raise
+ # ENOENT, pop-up a Windows GUI error for a non-ready partition or
+ # just hang
+ continue
- usage = psutil.disk_usage(disk.mountpoint)
- result.append(
- (
- disk.mountpoint,
- humanize_bytes(usage.used),
- humanize_bytes(usage.total),
- colorize_percent(usage.percent, warning=70, critical=85),
- )
- )
+ usage = psutil.disk_usage(disk.mountpoint)
+ result.append((
+ disk.mountpoint,
+ humanize_bytes(usage.used),
+ humanize_bytes(usage.total),
+ colorize_percent(usage.percent, warning=70, critical=85),
+ ))
- return result
+ return result
def _get_battery():
- if not hasattr(psutil, "sensors_battery"):
- return None
+ if not hasattr(psutil, "sensors_battery"):
+ return None
- try:
- battery = psutil.sensors_battery()
- except Exception as e:
- print("Error in _get_battery:", e)
- return None
+ try:
+ battery = psutil.sensors_battery()
+ except Exception as e:
+ print("Error in _get_battery:", e)
+ return None
- if battery is None:
- return None
+ if battery is None:
+ return None
- percent = battery.percent
- if battery.power_plugged:
- status = "charging" if percent < 100 else "fully charged"
- else:
- status = "%s left" % humanize_timedelta(timedelta(seconds=battery.secsleft))
- return colorize_percent(percent, critical=10, warning=20, inverse=True), status
+ percent = battery.percent
+ if battery.power_plugged:
+ status = "charging" if percent < 100 else "fully charged"
+ else:
+ status = "%s left" % humanize_timedelta(timedelta(seconds=battery.secsleft))
+ return colorize_percent(percent, critical=10, warning=20, inverse=True), status
def _get_local_ipv4_addresses():
- result = []
+ result = []
- for interface, addresses in psutil.net_if_addrs().items():
- for address in addresses:
- if address.family != socket.AF_INET:
- # allow only IPv4 addresses (skip IPv6 and MAC, for example)
- continue
- if interface.startswith("lo"):
- # skip loopback interfaces
- continue
+ for interface, addresses in psutil.net_if_addrs().items():
+ for address in addresses:
+ if address.family != socket.AF_INET:
+ # allow only IPv4 addresses (skip IPv6 and MAC, for example)
+ continue
+ if interface.startswith("lo"):
+ # skip loopback interfaces
+ continue
- result.append((interface, address.address))
+ result.append((interface, address.address))
- return result
+ return result
def _get_distro_info():
- if psutil.WINDOWS:
- return "windows", platform.system(), platform.release(), ""
- elif psutil.OSX:
- import plistlib
+ if psutil.WINDOWS:
+ return "windows", platform.system(), platform.release(), ""
+ elif psutil.OSX:
+ import plistlib
- with open("/System/Library/CoreServices/SystemVersion.plist", "rb") as f:
- sw_vers = plistlib.load(f)
- return "mac", sw_vers["ProductName"], sw_vers["ProductVersion"], ""
- elif _is_android():
- from subprocess import check_output
+ with open("/System/Library/CoreServices/SystemVersion.plist", "rb") as f:
+ sw_vers = plistlib.load(f)
+ return "mac", sw_vers["ProductName"], sw_vers["ProductVersion"], ""
+ elif _is_android():
+ from subprocess import check_output
- android_version = check_output(["getprop", "ro.build.version.release"])
- return "android", "Android", android_version.decode().strip(), ""
- elif psutil.LINUX:
- import distro
+ android_version = check_output(["getprop", "ro.build.version.release"])
+ return "android", "Android", android_version.decode().strip(), ""
+ elif psutil.LINUX:
+ import distro
- return distro.id(), distro.name(), distro.version(), distro.codename()
+ return distro.id(), distro.name(), distro.version(), distro.codename()
- raise NotImplementedError("unsupported OS")
+ raise NotImplementedError("unsupported OS")
def _is_android():
- return os.path.isdir("/system/app") and os.path.isdir("/system/priv-app")
+ return os.path.isdir("/system/app") and os.path.isdir("/system/priv-app")
diff --git a/scripts/copy-crosscode-emoji-url b/scripts/copy-crosscode-emoji-url
index 1fcbdc4..f5516a9 100755
--- a/scripts/copy-crosscode-emoji-url
+++ b/scripts/copy-crosscode-emoji-url
@@ -9,88 +9,76 @@ from typing import Any, Generator, Optional, Union
import urllib.parse
import urllib.request
+
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "script-resources"))
import common_script_utils
DEFAULT_REGISTRY_DUMP_URL = "https://stronghold.crosscode.ru/~ccbot/emote-registry.json"
-
if os.name == "posix":
- config_path: Path = (
- common_script_utils.DOTFILES_CONFIG_DIR / "copy-crosscode-emoji-url.ini"
- )
- default_registry_dump_file: Path = (
- common_script_utils.DOTFILES_CACHE_DIR / "dotfiles"
- )
+ config_path: Path = (common_script_utils.DOTFILES_CONFIG_DIR / "copy-crosscode-emoji-url.ini")
+ default_registry_dump_file: Path = (common_script_utils.DOTFILES_CACHE_DIR / "dotfiles")
else:
- common_script_utils.platform_not_supported_error()
+ common_script_utils.platform_not_supported_error()
config = ConfigParser(interpolation=None)
config.read(config_path)
-
emotes: list[dict[str, Any]] = []
def emote_downloader_and_iterator() -> Generator[str, None, None]:
- global emotes
+ global emotes
- registry_dump_file: Optional[Union[str, Path]] = config.get(
- "default", "ccbot_emote_registry_dump_file", fallback=None
- )
- if registry_dump_file is not None:
- registry_dump_file = os.path.expanduser(registry_dump_file)
- else:
- registry_dump_file = default_registry_dump_file
+ registry_dump_file: Optional[Union[
+ str, Path]] = config.get("default", "ccbot_emote_registry_dump_file", fallback=None)
+ if registry_dump_file is not None:
+ registry_dump_file = os.path.expanduser(registry_dump_file)
+ else:
+ registry_dump_file = default_registry_dump_file
- registry_dump_url = config.get(
- "default", "ccbot_emote_registry_dump_url", fallback=DEFAULT_REGISTRY_DUMP_URL
- )
+ registry_dump_url = config.get(
+ "default", "ccbot_emote_registry_dump_url", fallback=DEFAULT_REGISTRY_DUMP_URL
+ )
- emote_registry_data: dict[str, Any]
- try:
- with open(registry_dump_file, "r") as f:
- emote_registry_data = json.load(f)
- except FileNotFoundError:
- with urllib.request.urlopen(registry_dump_url, timeout=10) as response:
- emote_registry_data = json.load(response)
+ emote_registry_data: dict[str, Any]
+ try:
+ with open(registry_dump_file, "r") as f:
+ emote_registry_data = json.load(f)
+ except FileNotFoundError:
+ with urllib.request.urlopen(registry_dump_url, timeout=10) as response:
+ emote_registry_data = json.load(response)
- assert emote_registry_data["version"] == 1
+ assert emote_registry_data["version"] == 1
- emotes = [emote for emote in emote_registry_data["list"]
- # if emote["safe"]
- ]
+ emotes = [emote for emote in emote_registry_data["list"]]
- for emote in emotes:
- yield "{emote[ref]} [{emote[guild_name]}]".format(emote=emote)
+ for emote in emotes:
+ yield "{emote[ref]} [{emote[guild_name]}]".format(emote=emote)
chosen_index = common_script_utils.run_chooser(
- emote_downloader_and_iterator(), prompt="emote", async_read=True
+ emote_downloader_and_iterator(), prompt="emote", async_read=True
)
if chosen_index >= 0:
- chosen_emote = emotes[chosen_index]
+ chosen_emote = emotes[chosen_index]
- emote_url: urllib.parse.ParseResult = urllib.parse.urlparse(chosen_emote["url"])
- emote_url_query: dict[str, list[str]] = urllib.parse.parse_qs(emote_url.query)
+ emote_url: urllib.parse.ParseResult = urllib.parse.urlparse(chosen_emote["url"])
+ emote_url_query: dict[str, list[str]] = urllib.parse.parse_qs(emote_url.query)
- if config.getboolean("default", "add_emote_name_to_url", fallback=False):
- emote_url_query["name"] = [chosen_emote["name"]]
+ if config.getboolean("default", "add_emote_name_to_url", fallback=False):
+ emote_url_query["name"] = [chosen_emote["name"]]
- default_emote_image_size = config.getint(
- "default", "default_emote_image_size", fallback=None
- )
- if default_emote_image_size is not None:
- emote_url_query["size"] = [str(default_emote_image_size)]
+ default_emote_image_size = config.getint("default", "default_emote_image_size", fallback=None)
+ if default_emote_image_size is not None:
+ emote_url_query["size"] = [str(default_emote_image_size)]
- emote_url_query_str = urllib.parse.urlencode(emote_url_query, doseq=True)
- emote_url_str = urllib.parse.urlunparse(
- emote_url._replace(query=emote_url_query_str)
- )
+ emote_url_query_str = urllib.parse.urlencode(emote_url_query, doseq=True)
+ emote_url_str = urllib.parse.urlunparse(emote_url._replace(query=emote_url_query_str))
- common_script_utils.set_clipboard(emote_url_str)
+ common_script_utils.set_clipboard(emote_url_str)
- common_script_utils.send_notification(
- os.path.basename(__file__),
- "copied URL of {} to clipboard!".format(chosen_emote["ref"]),
- )
+ common_script_utils.send_notification(
+ os.path.basename(__file__),
+ "copied URL of {} to clipboard!".format(chosen_emote["ref"]),
+ )
diff --git a/scripts/discord-snowflake b/scripts/discord-snowflake
index 25380b9..85343ba 100755
--- a/scripts/discord-snowflake
+++ b/scripts/discord-snowflake
@@ -6,17 +6,16 @@ import sys
import colorama
import time
+
DISCORD_EPOCH = 1420070400000 # milliseconds
user_snowflake = int(sys.argv[1])
def print_field(name, value):
- print(
- "{}{}:{} {}".format(
- colorama.Style.BRIGHT, name.rjust(21), colorama.Style.RESET_ALL, value
- )
- )
+ print(
+ "{}{}:{} {}".format(colorama.Style.BRIGHT, name.rjust(21), colorama.Style.RESET_ALL, value)
+ )
creation_time = (user_snowflake >> 22) + DISCORD_EPOCH
@@ -25,11 +24,11 @@ internal_process_id = (user_snowflake >> 12) & 0x1F
increment = user_snowflake & 0xFFF
print_field(
- "Created at",
- "{}.{}".format(
- time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(creation_time // 1000)),
- creation_time % 1000,
- ),
+ "Created at",
+ "{}.{}".format(
+ time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(creation_time // 1000)),
+ creation_time % 1000,
+ ),
)
print_field("Internal worker ID", internal_worker_id)
print_field("Internal process ID", internal_process_id)
diff --git a/scripts/discord-stream-desktop-audio b/scripts/discord-stream-desktop-audio
index 0161def..1812557 100755
--- a/scripts/discord-stream-desktop-audio
+++ b/scripts/discord-stream-desktop-audio
@@ -4,35 +4,33 @@ import discord
import sys
import os
+
guild_id = int(sys.argv[1])
voice_channel_id = int(sys.argv[2])
pulseaudio_device = sys.argv[3]
with open(os.path.expanduser("~/.config/dotfiles/discord-tools-user-token.txt")) as f:
- bot_token = f.read().strip()
-
+ bot_token = f.read().strip()
bot = discord.Client()
@bot.event
async def on_ready():
- print("logged in as {0} ({0.id})".format(bot.user))
+ print("logged in as {0} ({0.id})".format(bot.user))
- guild: discord.Guild = bot.get_guild(guild_id)
- if guild is None:
- raise Exception("guild not found")
- voice_channel: discord.VoiceChannel = guild.get_channel(voice_channel_id)
- if voice_channel is None:
- raise Exception("channel not found")
+ guild: discord.Guild = bot.get_guild(guild_id)
+ if guild is None:
+ raise Exception("guild not found")
+ voice_channel: discord.VoiceChannel = guild.get_channel(voice_channel_id)
+ if voice_channel is None:
+ raise Exception("channel not found")
- voice_client = await voice_channel.connect()
- print("connected to {0} ({0.id}) in {1} ({1.id})".format(voice_channel, guild))
+ voice_client = await voice_channel.connect()
+ print("connected to {0} ({0.id}) in {1} ({1.id})".format(voice_channel, guild))
- source = discord.FFmpegPCMAudio(pulseaudio_device, before_options="-f pulse")
- voice_client.play(
- source, after=lambda e: print("Player error: %s" % e) if e else None
- )
+ source = discord.FFmpegPCMAudio(pulseaudio_device, before_options="-f pulse")
+ voice_client.play(source, after=lambda e: print("Player error: %s" % e) if e else None)
bot.run(bot_token, bot=False)
diff --git a/scripts/discord-whois b/scripts/discord-whois
index 91fd346..0598fed 100755
--- a/scripts/discord-whois
+++ b/scripts/discord-whois
@@ -18,22 +18,21 @@ import typing
DISCORD_EPOCH = 1420070400000 # milliseconds
# https://discord.com/developers/docs/resources/user#user-object-user-flags
DISCORD_FLAGS = {
- "Discord Employee": 1 << 0,
- "Discord Partner": 1 << 1,
- "HypeSquad Events": 1 << 2,
- "Bug Hunter Level 1": 1 << 3,
- "House of Bravery": 1 << 6,
- "House of Brilliance": 1 << 7,
- "House of Balance": 1 << 8,
- "Early Supporter": 1 << 9,
- "Team User": 1 << 10,
- "System": 1 << 12,
- "Bug Hunter Level 2": 1 << 14,
- "Verified Bot": 1 << 16,
- "Verified Bot Developer": 1 << 17,
+ "Discord Employee": 1 << 0,
+ "Discord Partner": 1 << 1,
+ "HypeSquad Events": 1 << 2,
+ "Bug Hunter Level 1": 1 << 3,
+ "House of Bravery": 1 << 6,
+ "House of Brilliance": 1 << 7,
+ "House of Balance": 1 << 8,
+ "Early Supporter": 1 << 9,
+ "Team User": 1 << 10,
+ "System": 1 << 12,
+ "Bug Hunter Level 2": 1 << 14,
+ "Verified Bot": 1 << 16,
+ "Verified Bot Developer": 1 << 17,
}
-
parser = argparse.ArgumentParser()
parser.add_argument("user_snowflake", type=int)
parser.add_argument("--bot-token", type=str)
@@ -45,32 +44,29 @@ user_snowflake = cli_args.user_snowflake
bot_token = cli_args.bot_token
if bot_token is None:
- with open(
- os.path.expanduser("~/.config/dotfiles/discord-tools-bot-token.txt")
- ) as f:
- bot_token = f.read().strip()
+ with open(os.path.expanduser("~/.config/dotfiles/discord-tools-bot-token.txt")) as f:
+ bot_token = f.read().strip()
image_size = cli_args.image_size
if not (image_size is None or (image_size > 0 and image_size & (image_size - 1)) == 0):
- parser.error("image_size must be greater than zero and a power of two")
-
+ parser.error("image_size must be greater than zero and a power of two")
try:
- opener = urllib.request.build_opener()
- # Don't send the User-Agent header, Discord blocks the default one
- opener.addheaders = []
- with opener.open(
- urllib.request.Request(
- "http://discord.com/api/users/{}".format(user_snowflake),
- headers={"Authorization": "Bot {}".format(bot_token)},
- ),
- timeout=10,
- ) as response:
- raw_data = json.load(response)
+ opener = urllib.request.build_opener()
+ # Don't send the User-Agent header, Discord blocks the default one
+ opener.addheaders = []
+ with opener.open(
+ urllib.request.Request(
+ "http://discord.com/api/users/{}".format(user_snowflake),
+ headers={"Authorization": "Bot {}".format(bot_token)},
+ ),
+ timeout=10,
+ ) as response:
+ raw_data = json.load(response)
except urllib.error.HTTPError as err:
- print(err, file=sys.stderr)
- print(err.read(), file=sys.stderr)
- raise err
+ print(err, file=sys.stderr)
+ print(err.read(), file=sys.stderr)
+ raise err
data = {}
@@ -78,19 +74,17 @@ data["ID"] = raw_data["id"]
data["Name"] = "{}#{}".format(raw_data["username"], raw_data["discriminator"])
default_avatar_url = "https://cdn.discordapp.com/embed/avatars/{}.png".format(
- int(raw_data["discriminator"], 10) % 5
+ int(raw_data["discriminator"], 10) % 5
)
avatar_url = (
- "https://cdn.discordapp.com/avatars/{}/{}.{}".format(
- raw_data["id"],
- raw_data["avatar"],
- "gif" if raw_data["avatar"].startswith("a_") else "png",
- )
- if raw_data["avatar"] is not None
- else default_avatar_url
+ "https://cdn.discordapp.com/avatars/{}/{}.{}".format(
+ raw_data["id"],
+ raw_data["avatar"],
+ "gif" if raw_data["avatar"].startswith("a_") else "png",
+ ) if raw_data["avatar"] is not None else default_avatar_url
)
if image_size is not None:
- avatar_url += "?size={}".format(image_size)
+ avatar_url += "?size={}".format(image_size)
data["Avatar"] = avatar_url
data["Default avatar"] = default_avatar_url
@@ -101,38 +95,37 @@ data["System user"] = raw_data.get("system", False)
# https://discord.com/developers/docs/reference#convert-snowflake-to-datetime
snowflake_creation_time = (user_snowflake >> 22) + DISCORD_EPOCH
data["Created at"] = "{}.{} UTC".format(
- time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(snowflake_creation_time // 1000)),
- snowflake_creation_time % 1000,
+ time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(snowflake_creation_time // 1000)),
+ snowflake_creation_time % 1000,
)
user_flags = raw_data["public_flags"]
if user_flags == 0:
- data["Flags"] = ""
+ data["Flags"] = ""
else:
- user_flag_names = []
- for flag_name, bitmask in DISCORD_FLAGS.items():
- if user_flags & bitmask:
- user_flag_names.append(flag_name)
- data["Flags"] = ", ".join(user_flag_names)
-
+ user_flag_names = []
+ for flag_name, bitmask in DISCORD_FLAGS.items():
+ if user_flags & bitmask:
+ user_flag_names.append(flag_name)
+ data["Flags"] = ", ".join(user_flag_names)
if cli_args.get_prop is None:
- max_name_length = max(map(len, data.keys()))
- for name, value in data.items():
+ max_name_length = max(map(len, data.keys()))
+ for name, value in data.items():
- if value is True:
- value = "yes"
- elif value is False:
- value = "no"
+ if value is True:
+ value = "yes"
+ elif value is False:
+ value = "no"
- print(
- "{}{:>{}}:{} {}".format(
- colorama.Style.BRIGHT,
- name,
- max_name_length + 1,
- colorama.Style.RESET_ALL,
- value,
- )
- )
+ print(
+ "{}{:>{}}:{} {}".format(
+ colorama.Style.BRIGHT,
+ name,
+ max_name_length + 1,
+ colorama.Style.RESET_ALL,
+ value,
+ )
+ )
else:
- print(data[cli_args.get_prop])
+ print(data[cli_args.get_prop])
diff --git a/scripts/factorio-dump-mod-settings b/scripts/factorio-dump-mod-settings
index 5f04b2e..8530465 100755
--- a/scripts/factorio-dump-mod-settings
+++ b/scripts/factorio-dump-mod-settings
@@ -10,31 +10,29 @@ from pathlib import Path
import struct
import json
+
sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "script-resources"))
import factorio.property_tree
-
with open(Path.home() / ".factorio" / "mods" / "mod-settings.dat", "rb") as f:
- version_main: int
- version_major: int
- version_minor: int
- version_developer: int
- version_main, version_major, version_minor, version_developer = struct.unpack(
- " Union[str, list[int]]:
- if encoding == "utf8":
- try:
- return b.decode("utf8")
- except UnicodeDecodeError:
- return list(b)
- elif encoding == "base16":
- return base64.b16encode(b).decode("ascii")
- elif encoding == "base32":
- return base64.b32encode(b).decode("ascii")
- elif encoding == "base64":
- return base64.b64encode(b).decode("ascii")
- elif encoding == "base85":
- return base64.b85encode(b).decode("ascii")
- else:
- assert False
+ if encoding == "utf8":
+ try:
+ return b.decode("utf8")
+ except UnicodeDecodeError:
+ return list(b)
+ elif encoding == "base16":
+ return base64.b16encode(b).decode("ascii")
+ elif encoding == "base32":
+ return base64.b32encode(b).decode("ascii")
+ elif encoding == "base64":
+ return base64.b64encode(b).decode("ascii")
+ elif encoding == "base85":
+ return base64.b85encode(b).decode("ascii")
+ else:
+ assert False
key_encoding: str = cli_args.key_encoding or cli_args.encoding
value_encoding: str = cli_args.value_encoding or cli_args.encoding
db = plyvel.DB(str(cli_args.db_path), create_if_missing=False)
with db.iterator() as iterator:
- for key, value in iterator:
- json.dump(
- {
- "key": bytes_to_json(key, key_encoding),
- "value": bytes_to_json(value, value_encoding),
- },
- stdout,
- )
- stdout.write("\n")
+ for key, value in iterator:
+ json.dump(
+ {
+ "key": bytes_to_json(key, key_encoding),
+ "value": bytes_to_json(value, value_encoding),
+ },
+ stdout,
+ )
+ stdout.write("\n")
diff --git a/scripts/mark-as-recently-used b/scripts/mark-as-recently-used
index 63475cd..c35e763 100755
--- a/scripts/mark-as-recently-used
+++ b/scripts/mark-as-recently-used
@@ -1,14 +1,16 @@
-#!/usr/bin/python3
+#!/usr/bin/env python3
# Taken from
import gi
import sys
+
gi.require_version("Gtk", "3.0")
-from gi.repository import Gtk, Gio, GLib # noqa E402
+from gi.repository import Gtk, Gio, GLib
+
rec_mgr = Gtk.RecentManager.get_default()
for arg in sys.argv[1:]:
- rec_mgr.add_item(Gio.File.new_for_path(arg).get_uri())
+ rec_mgr.add_item(Gio.File.new_for_path(arg).get_uri())
GLib.idle_add(Gtk.main_quit)
Gtk.main()
diff --git a/scripts/mediawiki-preview b/scripts/mediawiki-preview
index c1cfc68..b2d978b 100755
--- a/scripts/mediawiki-preview
+++ b/scripts/mediawiki-preview
@@ -38,7 +38,6 @@
# - The module `skins.citizen.scripts` references search inputs which aren't
# created by this script.
-
import argparse
import mwclient
import json
@@ -51,85 +50,85 @@ LANG = "en"
LANG_TEXT_DIRECTION = "ltr"
MODULES_POST_LOAD = {
- "vector": [
- "site",
- "mediawiki.page.startup",
- "mediawiki.page.ready",
- "mediawiki.toc",
- # "mediawiki.searchSuggest",
- # "mediawiki.page.watch.ajax",
- "skins.vector.js",
- ],
- "citizen": [
- # "site",
- # "mediawiki.page.startup",
- # "mediawiki.page.ready",
- # "mediawiki.toc",
- # "skins.citizen.scripts.toc",
- # "skins.citizen.scripts.search",
- # "skins.citizen.styles.search",
- # "skins.citizen.icons.search",
- # "skins.citizen.scripts",
- ],
+ "vector": [
+ "site",
+ "mediawiki.page.startup",
+ "mediawiki.page.ready",
+ "mediawiki.toc",
+ # "mediawiki.searchSuggest",
+ # "mediawiki.page.watch.ajax",
+ "skins.vector.js",
+ ],
+ "citizen": [
+ # "site",
+ # "mediawiki.page.startup",
+ # "mediawiki.page.ready",
+ # "mediawiki.toc",
+ # "skins.citizen.scripts.toc",
+ # "skins.citizen.scripts.search",
+ # "skins.citizen.styles.search",
+ # "skins.citizen.icons.search",
+ # "skins.citizen.scripts",
+ ],
}
MODULES_POST_LOAD_BLOCKED = {
- "citizen": [
- "skins.citizen.scripts.toc",
- "skins.citizen.scripts.search",
- "skins.citizen.styles.search",
- "skins.citizen.icons.search",
- ],
+ "citizen": [
+ "skins.citizen.scripts.toc",
+ "skins.citizen.scripts.search",
+ "skins.citizen.styles.search",
+ "skins.citizen.icons.search",
+ ],
}
MODULES_PRELOAD_STYLES = {
- "vector": [
- "mediawiki.legacy.commonPrint",
- "mediawiki.legacy.shared",
- "mediawiki.skinning.interface",
- "mediawiki.toc.styles",
- "skins.vector.styles",
- "site.styles",
- ],
- "citizen": [
- # "mediawiki.legacy.commonPrint",
- # "mediawiki.legacy.shared",
- "mediawiki.skinning.content.externallinks",
- # "mediawiki.toc.styles",
- "skins.citizen.icons",
- "skins.citizen.styles",
- "skins.citizen.icons.ca",
- "skins.citizen.icons.es",
- "skins.citizen.icons.footer",
- "skins.citizen.icons.n",
- "skins.citizen.icons.pt",
- "skins.citizen.icons.t",
- "skins.citizen.styles.fonts",
- "skins.citizen.styles.toc",
- "site.styles",
- ],
+ "vector": [
+ "mediawiki.legacy.commonPrint",
+ "mediawiki.legacy.shared",
+ "mediawiki.skinning.interface",
+ "mediawiki.toc.styles",
+ "skins.vector.styles",
+ "site.styles",
+ ],
+ "citizen": [
+ # "mediawiki.legacy.commonPrint",
+ # "mediawiki.legacy.shared",
+ "mediawiki.skinning.content.externallinks",
+ # "mediawiki.toc.styles",
+ "skins.citizen.icons",
+ "skins.citizen.styles",
+ "skins.citizen.icons.ca",
+ "skins.citizen.icons.es",
+ "skins.citizen.icons.footer",
+ "skins.citizen.icons.n",
+ "skins.citizen.icons.pt",
+ "skins.citizen.icons.t",
+ "skins.citizen.styles.fonts",
+ "skins.citizen.styles.toc",
+ "site.styles",
+ ],
}
MODULES_PRELOAD_SCRIPTS = {
- "vector": ["startup"],
- "citizen": ["startup"],
+ "vector": ["startup"],
+ "citizen": ["startup"],
}
# ported from
def escape_css_class(class_str):
- class_str = re.sub(
- r"""(^[0-9\-])|[\x00-\x20!"#$%&'()*+,.\/:;<=>?@[\]^`{|}~]|\xA0""",
- "_",
- class_str,
- )
- class_str = re.sub(r"_+", "_", class_str)
- class_str = class_str.rstrip("_")
- return class_str
+ class_str = re.sub(
+ r"""(^[0-9\-])|[\x00-\x20!"#$%&'()*+,.\/:;<=>?@[\]^`{|}~]|\xA0""",
+ "_",
+ class_str,
+ )
+ class_str = re.sub(r"_+", "_", class_str)
+ class_str = class_str.rstrip("_")
+ return class_str
def json_dumps_compact(data):
- return json.dumps(data, indent=None, separators=(",", ":"))
+ return json.dumps(data, indent=None, separators=(",", ":"))
parser = argparse.ArgumentParser()
@@ -137,50 +136,55 @@ parser.add_argument("--site", type=str, required=True)
parser.add_argument("--scheme", type=str, default="https")
parser.add_argument("--skin", type=str, default="vector")
parser.add_argument(
- "--input", type=str, required=True,
+ "--input",
+ type=str,
+ required=True,
)
parser.add_argument("--title", type=str)
parser.add_argument("--output", type=str, required=True)
cli_args = parser.parse_args()
-
site = mwclient.Site(cli_args.site, scheme=cli_args.scheme)
def get_load_script_url(**args):
- return "{path}load{ext}?{args}".format(
- path=site.path,
- ext=site.ext,
- args=urlencode({"lang": LANG, "skin": cli_args.skin, **args}),
- )
+ return "{path}load{ext}?{args}".format(
+ path=site.path,
+ ext=site.ext,
+ args=urlencode({
+ "lang": LANG,
+ "skin": cli_args.skin,
+ **args
+ }),
+ )
with open(cli_args.input, "r") as f:
- wikitext_str = f.read()
+ wikitext_str = f.read()
result = site.post(
- "parse",
- title=cli_args.title,
- text=wikitext_str,
- contentmodel="wikitext",
- prop="text|indicators|displaytitle|modules|jsconfigvars|categorieshtml",
- preview=True,
- pst=True, # pre-save transforms
- sectionpreview=False,
- disableeditsection=True, # disables "[edit]" links next to headers
- useskin=cli_args.skin,
- uselang=LANG,
+ "parse",
+ title=cli_args.title,
+ text=wikitext_str,
+ contentmodel="wikitext",
+ prop="text|indicators|displaytitle|modules|jsconfigvars|categorieshtml",
+ preview=True,
+ pst=True, # pre-save transforms
+ sectionpreview=False,
+ disableeditsection=True, # disables "[edit]" links next to headers
+ useskin=cli_args.skin,
+ uselang=LANG,
)["parse"]
def get_modules(page_modules, added_modules_dict, blocked_modules_dict={}):
- modules = page_modules + added_modules_dict[cli_args.skin]
- for blocked_module in blocked_modules_dict.get(cli_args.skin, []):
- try:
- modules.remove(blocked_module)
- except ValueError:
- pass
- return modules
+ modules = page_modules + added_modules_dict[cli_args.skin]
+ for blocked_module in blocked_modules_dict.get(cli_args.skin, []):
+ try:
+ modules.remove(blocked_module)
+ except ValueError:
+ pass
+ return modules
rendered_html = """\
@@ -240,53 +244,43 @@ rendered_html = """\