diff --git a/.README.md b/.README.md index 54ded0a..422562f 100644 --- a/.README.md +++ b/.README.md @@ -2,17 +2,7 @@ This is my own custom config that I use on my GNU/Linux machines. Not meant to be used by anyone else. -# Table of contents. - -1. [Bootstrap.](#bootstrap) -2. [General info.](#general-info) -3. [Load Gnome settings.](#load-gnome-settings) -4. [Navigation.](#navigation) -5. [Nvim config.](#nvim-config) -6. [Bash commands.](#bash-commands) -7. [To-do later.](#to-do-later) - -Additional references can be found in [.doc](.doc) directory. +For references, go to the [doc directory](.doc). # Bootstrap. @@ -22,728 +12,6 @@ Additional references can be found in [.doc](.doc) directory. curl -s https://git.voronind.com/voronind/linux/raw/branch/master/.bootstrap.sh | bash && source .bashrc ``` -# General info. - -It includes: -1. Git config (excluding user info). -2. Bash scripts and environment. -3. Tmux config. -4. Basic directory structure as well as redefining them as default. -5. Custom bin directory. -6. Collection of Linux configs (sshd, gnome, sysctl etc). -7. GTK 3/4 configs. -8. Htop config. -9. Nvim config. -10. SSH config. -11. Custom background. -12. Flatpak overrides. -13. Custom fonts. -14. MangoHud config. - # Load Gnome settings. To load Gnome settings run `dconf_load`. - -# Navigation. - -Navigation principles are shared between Gnome, Tmux and Nvim. The only difference is the *"Leader"* key. Gnome uses *Super* key, Tmux uses *Meta (alt)* key and Nvim uses *Space*. The rest somewhat repeats itself. - -## Gnome - -Key|Action ----|--- -`Super+Esc`|Lauch Terminal emulator. -`Super+q`|Switch to the left workspace. -`Super+e`|Switch to the right workspace. -`Super+Q`|Move window to the left workspace. -`Super+E`|Move window to the right workspace. -`Super+\|`|None. -`Super+-`|None. -`Super+w`|Toggle window maximize. -`Super+s`|Minimize window. -`Super+a`|Snap window to the left. -`Super+d`|Snap window to the right. -`Super+z`|Lock session. -`Super+x`|Close window. -`Super+c`|Minimize all windows. -`Super+v`|Take a screenshot. -`Super+f`|Toggle window fullscreen. - -## Tmux. - -Key|Action ----|--- -`Meta+Esc`, `Meta+t`|New window. `Meta+t` is for the Termux Android app as it can't send the `Meta+Esc` combo. -`Meta+q`|Switch to the left window. -`Meta+e`|Switch to the right window. -`Meta+Q`|Move window to the left. -`Meta+E`|Move window to the right. -`Meta+\|`|Split vertically. -`Meta+-`|Split horizontally. -`Meta+w`|Switch to the above split. -`Meta+s`|Switch to the below split. -`Meta+a`|Switch to the left split. -`Meta+d`|Switch to the right split. -`Meta+z`|Detach from session. -`Meta+x`|Close window. -`Meta+c`|Close split. -`Meta+v`|Visual selection. `y` to copy. -`Meta+f`|None. - -## Nvim. - -Key|Action ----|--- -`Space+Esc`|None. -`Space+q`|Switch to the left buffer. -`Space+e`|Switch to the right buffer. -`Space+Q`|Move buffer to the left. -`Space+E`|Move buffer to the right. -`Space+\|`|Split vertically. -`Space+-`|Split horizontally. -`Space+w`|Switch to the above split. -`Space+s`|Switch to the below split. -`Space+a`|Switch to the left split. -`Space+d`|Switch to the right split. -`Space+z`|Save all and exit. -`Space+x`|Close buffer. -`Space+c`|Close split. -`Space+v`|Visual selection (or just default `v`). -`Space+f`|None. - -More info in [Nvim config.](#nvim-config) - -# Nvim config. - -TODO: preserve default shortcuts, only add new ones when adding new functionality. - -## General info. - -* Run `:Update` to update everything. -* File tree shows everything by default, telescope ingores git-ignored files. - -## Keymaps. - -### Common. TODO: separate visual and others from common. - -Mode|Key|Action ----|---|--- -Normal, Visual|`5dd`|Repeat following command N (5) times. -Normal|`.`|Repeat input on selected line. -Normal, Visual|`.`|Repeat command on selected line(s). -Normal|`zz`|Save all files. -Normal|`ZZ`, `z`|Save all and quit. -Normal|`ZQ`|Quit without saving. -Normal|`v`, `v`|Visual selection (cursor). -Normal|`V`|Visual selection (lines). -Normal|``|Visual selection (block). -Normal|`gh`|Go to the start of the line. -Normal|`gl`|Go to the end of the line. -Normal|`gj`|Go to the end of the file. -Normal|`gk`|Go to the top of the file. -Normal|`u`|Undo action. -Normal|`U`|Redo action (*remaps*: undo whole line), (*default*: ``). -Visual|`u`|Convert selection to lowercase. -Visual|`U`|Convert selection to uppercase. -Visual|`~`|Toggle case. -Normal, Visual|`;`|Enter command mode (*default*: `:`). -Normal|`0`|Open shortcuts help. - -### Align. - -Mode|Key|Action ----|---|--- -Visual|`A`|Align selection from the right. -Visual|`a`|Align selection from the left. - -### Autocomplete. - -Mode|Key|Action ----|---|--- -Input|``|Autocomplete. -Normal|``|LSP autocomplete. - -### Comments. - -Mode|Key|Action ----|---|--- -Normal, Visual|`/`|Toggle selected line(s) comment. - -### File tree. - -Mode|Key|Action ----|---|--- -Normal|`1`|Toggle file tree. -Normal|``|Toggle directory or open file for preview. -Normal|`a`|Create file/directory. -Normal|`x`|Cut file/directory. -Normal|`p`|Paste file/directory. -Normal|`f`|Filter. -Normal|`F`|Reset filter. -Normal|`d`|Delete file/directory. -Normal|`r`|Rename file. -Normal|`R`|Refresh. -Normal|`s`|Open in system app. -Normal|`S`|Search. -Normal|`I`|Toggle gitignore filter. -Normal|`y`|Copy name. -Normal|`Y`|Copy relative path. - -### Fold. - -Mode|Key|Action ----|---|--- -Normal|`o`|Toggle fold. -Normal|`O`|Fold everything. - -### Git. - -Mode|Key|Action ----|---|--- -Normal|`g`|Toggle git inspection mode. - -### Macros. - -Mode|Key|Action ----|---|--- -Visual|`mwx`|Unwrap selection (select the stuff inside wraps). -Visual|`mw"`|Wrap selection in ". -Visual|`mw3"`|Wrap selection in 3x ". -Visual|`mw'`|Wrap selection in '. -Visual|`mw(`|Wrap selection in (). -Visual|`mw{`|Wrap selection in {}. -Visual|`mw[`|Wrap selection in []. -Visual|`` mw` ``|Wrap selection in \`. -Visual|`` mw3` ``|Wrap selection in 3x \`. -Visual|`mw*`|Wrap selection in *. -Visual|`mw2*`|Wrap selection in 2x *. -Visual|`mw3*`|Wrap selection in 3x *. -Visual|`mw `|Wrap selection in spaces. -Normal, Visual|`mmx`|Markdown: set - [ ] as completed. -Normal, Visual|`mm `|Markdown: set - [x] as not completed. -Normal|`mmp`|Markdown: insert paragrapg (2x non-breakable spaces). -Visual|`mmb`|Markdown: make selection bold. -Visual|`mmi`|Markdown: make selection italic. -Visual|`mms`|Markdown: make selection strikethrough. -Visual|`mmr`|Markdown: make selection a reference. -Visual|`mmc`|Markdown: make selection a code block. -Normal|`mi`|Copy and increment selected line. -Normal|`ma`|Select all. - -### Navigation. - -Mode|Key|Action ----|---|--- -Normal|`w`|Switch to the split above. -Normal|`a`|Switch to the split left. -Normal|`s`|Switch to the split below. -Normal|`d`|Switch to the split right. -Normal|`q`|Swtich to the buffer left. -Normal|`e`|Swtich to the buffer right. -Normal|`Q`|Move the buffer left. -Normal|`E`|Move the buffer right. -Normal|`x`|Close the buffer. -Normal|`X`|Close all invisible buffers. -Normal|`m`|Move split. -Normal|`\|`|Split vertically. -Normal|`-`|Split horizontally. -Normal|`c`|Close split. -Input|``|Move left. -Input|``|Move right. -Input|``|Move down. -Input|``|Move up. - -### Telescope. - -Mode|Key|Action ----|---|--- -Normal|`ff`|Find files. -Normal|`fg`|Find grep (find text within files). -Normal|`fb`|Find buffer. -Normal|`fh`|Find help. -Normal|`ft`|Find treesitter (vars, functions etc). -Normal|`fa`|Find all (default treesitter window). - -### Terminal. - -Mode|Key|Action ----|---|--- -Normal|`4`|Open terminal. -Terminal|``|Detach from terminal. - -### To-do. - -Write `TODO:` or `NOTE:` to make it searchable. - -Mode|Key|Action ----|---|--- -Normal|`3`|Open to-do list. - -### Trouble. - -Mode|Key|Action ----|---|--- -Normal|`2`|Open LSP trouble list. - -### Which key. - -Mode|Key|Action ----|---|--- -Normal|`0`|Show context hotkey help. - -### Window management. - -Mode|Key|Action ----|---|--- -Normal|`-`|Decrease split size vertically. -Normal|`_`|Increase split size vertically. -Normal|`\`|Decrease split size horizontally. -Normal|`\|`|Increase split size horizontally. -Normal|`=`|Equalize split sizes. - -# Bash commands. - -To get help with usage info run: - -```text -$ help - -or - -$ h -``` - -## Android. - -Command|Description ----|--- -`emulator [NAME]`|Starts an Android emulator. Default name is "default". - -## Archive. - -Those are self-written scripts to create archives. They are basically compressed tar archives with SHA1 hashes in their names. They are exported so also available in `parallel` like this: `ls | parallel -j 8 -- archive {}` - -Command|Description ----|--- -`archive [DIRS]`|Create archive with the best compression (slow). If no args given, archives all files in current directory as separate archives. -`archive_fast [FILES]`|Like normal `archive` but with minimal compression. -`archive_check [ARCHIVES]`|Check specified archives or all archives in current directory. -`archive_name [ARCHIVES] [NAME]`|Rename specified archive ro specified name or simplify name for specified archive or simplify names for all archives. -`archive_prune [NAME]`|Delete old versions of an archive, or all archives by default. -`unarchive [ARCHIVES]`|Check specified or all archives and extract if they are correct. - -## Autocomplete. - -Thos are functions that provide tab-completions. - -```bash -_foo() -{ - _autocomplete "{foo,bar}" -} -complete -F _foo foo -``` - -Command|Description ----|--- -`_autocomplete `|Provide completion based on provided arguments separated by spaces. -`_autocomplete_first `|Same as `_autocomplete` but works only once for first argument. -`_autocomplete_grep `|Ls autocomplete with specified grep filter. -`_autocomplete_nested`|Provides nested completions, just like `sudo` does. - -## Battery. - -Command|Description ----|--- -`battery_level`|Print battery charge level (if available). - -## Bootstrap. - -Shortcuts to install different stuff. - -Command|Description ----|--- -`bootstrap_cargo`|Install cargo. -`bootstrap_texlive`|Install TeXLive package. -`bootstrap_grub`|Install grub theme. Requires root. -`bootstrap_ffmpeg`|Install ffmpeg in flatpak to make `~/app/bin/ffmpeg` work. - -## Cd. - -Command|Description ----|--- -`cdd `|Cd back to previous directory by name. - -## Checksum. - -Command|Description ----|--- -`checksum_create [FILES]`|Create checksums for files in current directory. -`checksum_check [FILES]`|Check previously created checksums. - -## Chmod. - -Command|Description ----|--- -`x `|Make file executable. - -## Color. - -### How to use. - -Most of the time you want to use it with `echo`. To make `echo` respect colors, you need to use `-e` flag like that: -```bash -export color_default="\033[0m" -export color_red="\033[0;31m" -echo -e "${color_red}hello world!${color_default}" # will print "hello world!" in red. -``` -Don't forget to use `color_default` at the end, or your whole terminal will be red. - -### List of colors. - -Please note that colors depend on Terminal Emulator and may vary based on its settings. - -|Color|Code| -|---|---| -|default|`\033[0m`| -|blue|`\033[0;34m`| -|blue (bold)|`\033[1;34m`| -|cyan|`\033[0;36m`| -|cyan (bold)|`\033[1;36m`| -|green|`\033[0;32m`| -|green (bold)|`\033[1;32m`| -|purple|`\033[0;35m`| -|purple (bold)|`\033[1;35m`| -|red|`\033[0;31m`| -|red (bold)|`\033[1;31m`| -|white|`\033[0;37m`| -|white (bold)|`\033[1;37m`| -|yellow|`\033[0;33m`| -|yellow (bold)|`\033[1;33m`| - -## Copy/paste. - -Command|Description ----|--- -`echo a \| copy`|Copy `a` to system clipboard. -`paste > file.txt`|Paste system clipboard to a file (or pipe). - -## File copy (cp). - -Command|Description ----|--- -`cp `|Copy files or dirs. Actually, it is an alias for `rsync -ahP`. Multiple `` could be specified. -`cp_merge `|Mirror directories. Same as `rsync --delete`. -`cp_link `|Copy directory by recursively creating hardlinks and directories. -`cp_test `|Test cp_merge without writing anything. -`bcp `|Default `cp` command. - -## Date. - -Command|Description ----|--- -`today`|Return today's date in `YYYYmmdd` format. -`dow`|Return today's day of week, where 1 is Monday. - -## Dconf (gnome settings). - -Command|Description ----|--- -`dconf_load`|Load custom settings. -`dconf_save`|Export all current setting in a file to inspect. - -## Disk. - -Command|Description ----|--- -`df`|Show free disk space (only physical media). -`du [FILES]`|Show disk usage. - -## Docker. - -Command|Description ----|--- -`docker_volumes `|Show volumes of a specified container. -`docker_health`|Show containers that exited with an error code. -`docker_prune`|Heavy cleanup to free up space. -`docker_ip `|Show IP of a specified container. -`docker_update`|Update all Docker images. -`dc`|Short for `docker compose`. -`dcu [SERVICE]`|Start a compose service. -`dcd [SERVICE]`|Remove a compose service. -`dcp [SERVICE]`|Pull image for a compose service. -`dcl [SERVICE]`|Show logs for a compose service. -`dcr [SERVICE]`|Restart a compose service. -`dcs [SERVICE]`|Stop a compose service. -`dcdu [SERVICE]`|Recreate a compose service. -`dcpu [SERVICE]`|Update and recreate a compose service. -`dcul [SERVICE]`|Start a compose service and show its logs. - -## Environment variables. - -Variable|Description ----|--- -`PATH`|Defines where to find binaries. Modified to also include `$HOME/app/bin/` recursively. -`LANGUAGE`|Specifies `UTF-8` as default. -`EDITOR`|Specifies nvim as a default editor. -`MANPAGER`|Specifies nvim as a default `man` viewer. -`JAVA_HOME`|Specifies where JDK is stored. -`ANDROID_SDK_ROOT`|Specifies where Android SDK is stored. -`TEXMFVAR`, `TEXMFCONFIG`, `TEXMFLOCAL`|Specifies paths for TeXLive user directories. - -## Ffmpeg. - -Command|Description ----|--- -`ffmpeg_mux_audio `|Mux external audio into one container with video (replaces original audio). Run inside dir with original video. names should be the same for each video. -`ffmpeg_mux_cover `|Mux image into files of specified format. -`ffmpeg_music_meta `|Detect and update music metadata. - -## File. - -Command|Description ----|--- -`o `|Open file with the default GUI app. - -## Find. - -Command|Description ----|--- -`find_ext`|Find all file extensions recursively. -`find_function`|Find all dotfiles functions. - -## Fix. - -Contains simple fixes for various issues. - -Command|Description ----|--- -`fix_ethernet_speed `|Specify ethernet speed if it failed to set correct speed automatically. [SPEED] can be 10/100/1000 etc. -`fix_files_sftp`|Make Nautilus forget incorrect password for SFTP connection. - -## Git. - -Command|Description ----|--- -`gps`|Git push. -`gpsf`|Git push --force. -`gpl`|Git pull. -`gl`|Git log. -`gs`|Git status. -`gst`|Git stash. -`gd`|Git diff. -`gdc `|Git diff for a specific commit. -`gc `|Git commit. -`gch`|Git checkout. -`gchb`|Git checkout branch. -`gb`|Git branch. -`gbd `|Delete specified Git branch. -`gbda`|Delete all local branches except the current one. -`gf`|Git fetch --all. -`gt`|Git tag. -`gi`|Delete files updated in git ignore. -`gpc `|Git patch create. -`gp `|Git patch (apply). -`ga`|Git add with preview. -`gr [COUNT]`|Git rebase. 2 last commits by default. 0 means from root. -`gu `|Configure git user as Dmitry Voronin with specified email (project). -`gg `|Get git repo from my own git. -`ggc`|Run git garbage collection. - -## Help. - -Command|Description ----|--- -`help `|Get help for a dotfile function. -`h `|Same as `help`. - -## Ls. - -Command|Description ----|--- -`l`|List files in current dir. -`ll`|List files by mtime. -`lll [DEPTH] [DIRS]`|Show file tree. -`llll`|List everything recursively. -`la`|List all files. -`lla`|List all files by mtime. - -## Name. - -Those are scripts to manipulate file names. They are all exported and available for `parallel`. If no [FILES] specified, it applies to all files inside current directory. - -Command|Description ----|--- -`name [FILES]`|Replace all non-alphanumeric characters in file with underscores. -`name_hash [FILES]`|Replace all file names with hashes, keep extension. -`name_hash_check [FILES]`|Check all file hashes. -`name_series [FILES]`|Rename files to Jellyfin's show format: `Episode S01E01.mkv`. -`name_manga [FILES]`|Rename files to Kavita's manga format: `Name Vol.1 Ch.01.cbr`. -`name_ext [FILES]`|Change file extensions. -`name_prefix [FILES]`|Change file prefix. -`name_postfix [FILES]`|Change file postfix. -`name_replace [FILES]`|Replace a part of file name. - -## Ncdu. - -Command|Description ----|--- -`ncdu [DIR]`|Show recursive disk usage. Only on the same filesystem. - -## Notify. - -Command|Description ----|--- -`notify `|Send notification. -`notify_silent `|Send silent notification. - -## Own. - -Command|Description ----|--- -`own [USER] [FILE]`|Change ownership & permissions to specified user. Ownership changes only when root. - -## Pack. - -Command|Description ----|--- -`pack [FILES]`|Create desired file format from other files. -`unpack [FILES]`|Attempt to extract file content. - -## Parse. - -Command|Description ----|--- -`parse_simplify `|Return simplified string: only alnum, underscores and dashes. -`parse_camel `|Return simplified CamelCase string. -`parse_alnum `|Return string containing only alphanumeric characters. - -## Permissions. - -Command|Description ----|--- -`perm`|Recursively change permissions not to share: 700 for dirs and 600 for files. -`perm_share`|Recursively change permissions to share: 755 for dirs and 644 for files. - -## Ps. - -Command|Description ----|--- -`ps `|Show process info for matching [PROGRAM] name. - -## Recursive. - -Command|Description ----|--- -`recursive `|Cd into every directory recursively and run specified command in each dir. -`recursive1 `|Cd into every directory in current directory and run specified command in each dir. - -## Rust. - -Command|Description ----|--- -`rust_book`|Open Rust book in a browser. - -## Shopt. - -Shopt|Description ----|--- -`dotglob`|When using `*` to match files, hidden files that start with a dot are also included. -`globstar`|Allows the use of `**` for recursive search. -`autocd`|Change directories without writing `cd`. - -## Su. - -Command|Description ----|--- -`s`|An alias for `su` cause I'm lazy. - -## Terminal. - -Command|Description ----|--- -`tsize`|Prints terminal size. - -## Tmp. - -Command|Description ----|--- -`tmp`|CD into host's primary tmp dir. - -## Tmux. - -Command|Description ----|--- -`ta [NAME]`|Attach to session by name. Default is `main`. -`td`|Detach from session. -`tl`|List all sessions. -`trn [NAME]`|Rename session. Uses current dir name by default. -`tn [NAME]`|Name window. Uses current dir name by default. -`tk [NAME]`|Kill session. Default is `main`. -`tka`|Kill all sessions. - -## To-do. - -Command|Description ----|--- -`todo`|Open editor for `~/.todo.md` file. - -## Toolbx. - -Command|Description ----|--- -`tb [NAME]`|Attach to box by name. Default is `main`. -`tbk [NAME]`|Kill box by name. Default is `main`. -`tb_rpmfusion [NAME]`|Install RPMFusion package to box by name. Default is `main`. -`tbl`|List all boxes. - -## Transcode. -`transcode [FILES]`|Convert between different formats. - -## Try. - -Command|Description ----|--- -`try `|Repeat the command every 2 seconds until it exits with success. - -## Umask. - -By default, umask is `077` which means group and others have no access when files are created. - -## Util. - -Short util functions. - -Command|Description ----|--- -`_core_count`|Get number of available CPU threads. - -## Vdl. - -Command|Description ----|--- -`vdl [LINK]`|Download a video/playlist. When no link provided, tries to update previously downloaded link. - -## Vi. - -Command|Description ----|--- -`vi`|Run vim. -`v`|Run neovim. - -## Wallpaper. - -Command|Description ----|--- -`wallpaper `|Set specified file as a wallpaper. - -## Watch. - -Command|Description ----|--- -`w `|Alias for `watch`. -`ww `|Alias for `watch` that updates every 0.1 seconds. - -# To-do later. - -- [ ] Add tmux shortcuts to combo, too. diff --git a/.config/bash/module/android.sh b/.config/bash/module/android.sh index 435f332..c41e80e 100644 --- a/.config/bash/module/android.sh +++ b/.config/bash/module/android.sh @@ -1,3 +1,10 @@ +# Start an Android emulator. +# Default name is "default". +# Usage: emulator [NAME] function emulator() { - ${ANDROID_SDK_ROOT}/emulator/emulator -avd default &> /dev/null & disown + local name="${1}" + + [[ "${name}" = "" ]] && name="default" + + ${ANDROID_SDK_ROOT}/emulator/emulator -avd "${name}" &> /dev/null & disown } diff --git a/.config/bash/module/archive.sh b/.config/bash/module/archive.sh index 926a899..401609f 100644 --- a/.config/bash/module/archive.sh +++ b/.config/bash/module/archive.sh @@ -1,17 +1,14 @@ -export _ARCHIVE_PATTERN="_[0-9]{12}-[[:alnum:]]{40}.t[xg]z" +export _archive_pattern="_[0-9]{12}-[[:alnum:]]{40}.t[xg]z" -function _ARCHIVE_DATE() { - date +%Y%m%d%H%M -} - -# archive file with maximum compression and checksum. -# usage: archive [FILES] +# Archive directories. +# All directories by default. +# Usage: archive [DIRS] function archive() { local IFS=$'\n' local targets=("${@}") local count=0 local total=${#} - local date=$(_ARCHIVE_DATE) + local date=$(_archive_date) local failed=0 # Set dafult value to target all directories. @@ -51,14 +48,15 @@ function archive() { fi } -# archive file with minimal compression and checksum. -# usage: archive_fast [FILES] +# Archive directories with fast compression. +# All directories by default. +# Usage: archive_fast [DIRS] function archive_fast() { local IFS=$'\n' local targets=("${@}") local count=0 local total=${#} - local date=$(_ARCHIVE_DATE) + local date=$(_archive_date) local failed=0 # Set dafult value to target all directories. @@ -98,8 +96,9 @@ function archive_fast() { fi } -# check archive hashes. -# usage: archive_check [FILES] +# Check archives integrity. +# Checks all archives by default. +# Usage: archive_check [FILES] function archive_check() { local IFS=$'\n' local targets=("${@}") @@ -109,7 +108,7 @@ function archive_check() { # set dafult value to target all supported archives. if [[ "${targets}" = "" ]]; then - targets=($(ls | grep -E ${_ARCHIVE_PATTERN})) + targets=($(ls | grep -E ${_archive_pattern})) total=${#targets[@]} fi @@ -143,6 +142,7 @@ function archive_check() { } # Delete old versions of an archives. +# All archives by default. # Usage: archive_prune [NAME] function archive_prune() { local IFS=$'\n' @@ -153,7 +153,7 @@ function archive_prune() { # All archives by default. if [[ "${targets}" = "" ]]; then - targets=($(ls | grep -E ${_ARCHIVE_PATTERN})) + targets=($(ls | grep -E ${_archive_pattern})) total=${#targets[@]} fi @@ -193,8 +193,8 @@ function archive_prune() { fi } -# extract previously created archive with checksum validation. -# usage: unarchive [FILES] +# Extract previously created archive with checksum validation. +# Usage: unarchive [FILES] function unarchive() { local IFS=$'\n' local targets=("${@}") @@ -204,7 +204,7 @@ function unarchive() { # set dafult value to target all supported archives. if [[ "${targets}" = "" ]]; then - targets=($(ls | grep -E ${_ARCHIVE_PATTERN})) + targets=($(ls | grep -E ${_archive_pattern})) total=${#targets[@]} fi @@ -259,8 +259,10 @@ function unarchive() { fi } -# rename archive. if no name specified, it simplifies archive's name. -# usage: archive_name [ARCHIVE] [NAME] +# Rename archives. +# If no name specified, it simplifies archive's name. +# If no archives specified, apply to all archives. +# Usage: archive_name [ARCHIVE] [NAME] function archive_name() { local IFS=$'\n' local targets="${1}" @@ -271,7 +273,7 @@ function archive_name() { # set dafult value to target all supported archives. if [[ "${targets}" = "" ]]; then - targets=($(ls | grep -E ${_ARCHIVE_PATTERN})) + targets=($(ls | grep -E ${_archive_pattern})) total=${#targets[@]} fi @@ -323,7 +325,7 @@ function archive_name() { fi } -# convert an old archive to a new format. TODO: remove me after some time when there won't be any old archives. +# Convert old archives to a new format. TODO: remove me after some time when there won't be any old archives. function archive_convert() { local IFS=$'\n' local old_format="_[[:alnum:]]{40}.tar.[xg]z" @@ -366,6 +368,8 @@ function archive_convert() { done } +# Parse archive file name to get: name, date, hash and format. +# Usage: _archive_parse function _archive_parse() { local input="${1}" local name="${input%_*}" @@ -380,6 +384,8 @@ function _archive_parse() { echo "${format}" } +# Autocomplete for archive_name function. +# First arg is the archives list, second one is selected archive's current name. function _archive_name() { local IFS=$'\n' COMPREPLY=() @@ -389,7 +395,7 @@ function _archive_name() { local command="${COMP_WORDS[0]}" if [[ "${prev}" = "${command}" ]]; then - COMPREPLY=( $(compgen -W "$(ls | grep -E ${_ARCHIVE_PATTERN})" -- ${cur}) ) + COMPREPLY=( $(compgen -W "$(ls | grep -E ${_archive_pattern})" -- ${cur}) ) return 0 else local name="${prev%_*}" @@ -398,8 +404,14 @@ function _archive_name() { fi } +# Autocomplete with archives in current dir. function _archive_grep() { - _autocomplete_grep ${_ARCHIVE_PATTERN} + _autocomplete_grep ${_archive_pattern} +} + +# Get date for a new archive. +function _archive_date() { + date +%Y%m%d%H%M } complete -o filenames -F _archive_grep archive_check unarchive diff --git a/.config/bash/module/autocomplete.sh b/.config/bash/module/autocomplete.sh index 47b7f85..dee9dfe 100644 --- a/.config/bash/module/autocomplete.sh +++ b/.config/bash/module/autocomplete.sh @@ -1,6 +1,6 @@ -# bash autocomplete. -# usage: _foo() { _autocomplete "{foo,bar}" } ; complete -F _foo foo -# there are also options like -o nospace. see man for more info. +# Bash autocomplete. +# There are also options like -o nospace. see man for more info. +# Usage: _foo() { _autocomplete "{foo,bar}" } ; complete -F _foo foo function _autocomplete() { local IFS=$'\n' local commands="${*}" @@ -15,7 +15,7 @@ function _autocomplete() { return 0 } -# autocomplete only first argument. +# Autocomplete only first argument. function _autocomplete_first() { local IFS=$'\n' local commands="${*}" @@ -46,7 +46,7 @@ function _autocomplete_grep() { return 0 } -# autocomplete nested program. +# Autocomplete nested program. function _autocomplete_nested() { # local IFS=$'\n' local cur prev words cword split i diff --git a/.config/bash/module/battery.sh b/.config/bash/module/battery.sh index ebccd30..5c836c8 100644 --- a/.config/bash/module/battery.sh +++ b/.config/bash/module/battery.sh @@ -1,4 +1,4 @@ -# check battery level. +# Print current battery level. function battery_level() { cat /sys/class/power_supply/BAT*/capacity } diff --git a/.config/bash/module/bootstrap.sh b/.config/bash/module/bootstrap.sh index 721a1f2..3663bd5 100644 --- a/.config/bash/module/bootstrap.sh +++ b/.config/bash/module/bootstrap.sh @@ -1,10 +1,10 @@ -# install Cargo/Rust. +# Install Cargo/Rust. function bootstrap_rust() { curl https://sh.rustup.rs -sSf | sh rustup component add rust-analyzer } -# install TeXLive. +# Install TeXLive. function bootstrap_texlive() { cd /tmp wget https://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz @@ -14,14 +14,14 @@ function bootstrap_texlive() { ./install-tl } -# install grub theme. +# Install grub theme. function bootstrap_grub() { wget -O- https://github.com/shvchk/fallout-grub-theme/raw/master/install.sh | bash echo 'GRUB_HIDDEN_TIMEOUT=' >> /etc/default/grub grub2-mkconfig -o /etc/grub2.cfg } -# install ffmpeg. +# Install ffmpeg. function bootstrap_ffmpeg() { flatpak install org.kde.kdenlive } diff --git a/.config/bash/module/cd.sh b/.config/bash/module/cd.sh index 63b8fab..db32765 100644 --- a/.config/bash/module/cd.sh +++ b/.config/bash/module/cd.sh @@ -1,4 +1,5 @@ # CD (back) to directory. +# Finds first directory that matches the input (case-insensitive). # Usage: cdd function cdd() { local target="${1}" diff --git a/.config/bash/module/checksum.sh b/.config/bash/module/checksum.sh index 00054a7..fd07803 100644 --- a/.config/bash/module/checksum.sh +++ b/.config/bash/module/checksum.sh @@ -1,4 +1,6 @@ # Save file checksums. +# For file with a name "file" it will create a new file called ".file.sha1" with hash in it. +# All files by default. # Usage: checksum_create [FILES] function checksum_create() { local IFS=$'\n' @@ -46,6 +48,8 @@ function checksum_create() { } # Check stored values against actual files. +# All files by default. +# Usage: checksum_check [FILES] function checksum_check() { local IFS=$'\n' local targets=("${@}") @@ -95,16 +99,21 @@ function checksum_check() { fi } +# Calculate hashes for all files recursively and store in a file called "checksum.sha1". function checksum() { find -type f | parallel -j $(_core_count) -- sha1sum {} >> checksum.sha1 } +# Create checksum for a file. +# Usage: _checksum_create function _checksum_create() { local path="${1%/*}" local name="${1##*/}" sha1sum "${path}/${name}" > "${path}/.${name}.sha1" } +# Check checksum for a file. +# Usage: _checksum_check function _checksum_check() { local file="${1##*\ \ }" local stored="${1%%\ \ *}" diff --git a/.config/bash/module/chmod.sh b/.config/bash/module/chmod.sh index 85b5b9b..1580af6 100644 --- a/.config/bash/module/chmod.sh +++ b/.config/bash/module/chmod.sh @@ -1,4 +1,5 @@ -# add executable flag to file. +# Add executable flag to file. +# Usage: x function x() { - chmod +x "${@}" + chmod +x -- "${@}" } diff --git a/.config/bash/module/color.sh b/.config/bash/module/color.sh index f83c0b3..4596d82 100644 --- a/.config/bash/module/color.sh +++ b/.config/bash/module/color.sh @@ -1,6 +1,6 @@ -# collection of available CLI colors. -# they may differ depending on the terminal used. -# colors with 'b' prefix are bold colors. +# Collection of available CLI colors. +# They may differ depending on the terminal used. +# Colors with 'b' prefix are bold colors. export color_default="\033[0m" export color_blue="\033[0;34m" @@ -18,7 +18,7 @@ export color_bwhite="\033[1;37m" export color_yellow="\033[0;33m" export color_byellow="\033[1;33m" -# print all available colors with their names colored in corresponding color. +# Print all available colors with their names colored in corresponding color. function color_test() { echo -e "${color_default}color_default\n${color_blue}color_blue\n${color_bblue}color_bblue\n${color_cyan}color_cyan\n${color_bcyan}color_bcyan\n${color_green}color_green\n${color_bgreen}color_bgreen\n${color_purple}color_purple\n${color_bpurple}color_bpurple\n${color_red}color_red\n${color_bred}color_bred\n${color_white}color_white\n${color_bwhite}color_bwhite\n${color_yellow}color_yellow\n${color_byellow}color_byellow" } diff --git a/.config/bash/module/copypaste.sh b/.config/bash/module/copypaste.sh index 7b9b1a7..09d03b5 100644 --- a/.config/bash/module/copypaste.sh +++ b/.config/bash/module/copypaste.sh @@ -1,2 +1,9 @@ -alias copy="wl-copy" # copy stdin to system clipboard. -alias paste="wl-paste" # paste system clipboard to stdout. +# Copy stdin to system clipboard. Example: echo hi | copy +function copy() { + wl-copy +} + +# Paste system clipboard to stdout. Example: paste > file.txt +function paste() { + wl-paste +} diff --git a/.config/bash/module/cp.sh b/.config/bash/module/cp.sh index 25a17b1..d31435f 100644 --- a/.config/bash/module/cp.sh +++ b/.config/bash/module/cp.sh @@ -1,24 +1,30 @@ -# replace default cp with rsync. +# Replaces default cp with rsync. +# Usage: cp function cp() { rsync -ahP --chmod=u+w -- "${@}" } -# copy and also merge all changes (delete dst files that do not exist in src). +# Copy and also merge all changes (delete dst files that do not exist in src). +# Usage: cp_merge function cp_merge() { rsync -ahP --chmod=u+w --delete -- "${@}" } -# copy by creating hardlinks. +# Copy by creating hardlinks. +# Works for directories, too. +# Usage: cp_link function cp_link() { /usr/bin/cp -lr -- "${@}" } -# default cp, a.k.a builtin cp. +# Default cp, a.k.a builtin cp. +# When you don't need rsync. function bcp() { /usr/bin/cp "${@}" } -# cp_merge without writing anything. +# Print output of cp_merge without writing anything. +# Usage: cp_test function cp_test() { rsync -ahP --chmod=u+w --delete -n -- "${@}" } diff --git a/.config/bash/module/date.sh b/.config/bash/module/date.sh index 7bf68c8..45ff32f 100644 --- a/.config/bash/module/date.sh +++ b/.config/bash/module/date.sh @@ -1,9 +1,9 @@ -# print today date in yyyyMMdd format. +# Print today date in yyyyMMdd format. function today() { date +%Y%m%d } -# current day of week number. +# Current day of week number. function dow() { date +%u } diff --git a/.config/bash/module/dconf.sh b/.config/bash/module/dconf.sh index 947d21a..0e7ffc9 100644 --- a/.config/bash/module/dconf.sh +++ b/.config/bash/module/dconf.sh @@ -1,9 +1,16 @@ -export _GDCONF_PATH="${HOME}/.config/linux/gnome.dconf" +export _gdconf_path="${HOME}/.config/linux/gnome.dconf" +# Load Gnome settings. function dconf_load() { - sed -i -e s/voronind/$(whoami)/g ${_GDCONF_PATH} ; dconf load / < ${_GDCONF_PATH} + sed -i -e s/voronind/$(whoami)/g ${_gdconf_path} ; dconf load / < ${_gdconf_path} } +# Dump Gnome settings into the file. +# Default name is gnome.dconf. +# Do this before changing settings and after, an then run diff to find out what to add to main gnome.dconf. +# Usage: dconf_save [FILE] function dconf_save() { - dconf dump / > gnome.dconf + local name="${1}" + [[ "${name}" = "" ]] && name="gnome.dconf" + dconf dump / > "${name}" } diff --git a/.config/bash/module/disk.sh b/.config/bash/module/disk.sh index dd108e7..d6a2dd9 100644 --- a/.config/bash/module/disk.sh +++ b/.config/bash/module/disk.sh @@ -1,9 +1,11 @@ -# show only physical drive sizes. +# Show only physical drives info. function df() { - df --si | sed -e '1p' -e "/^\/dev\//!d" + /usr/bin/df --si | sed -e '1p' -e "/^\/dev\//!d" } -# show combined size in SI. +# Show combined size in SI. +# Current dir by default. +# Usage: du [DIRS] function du() { - du -sh --si -- "${@}" + /usr/bin/du -sh --si -- "${@}" } diff --git a/.config/bash/module/doc.sh b/.config/bash/module/doc.sh new file mode 100644 index 0000000..ff07c86 --- /dev/null +++ b/.config/bash/module/doc.sh @@ -0,0 +1,42 @@ +# Generate a markdown file with all the help info. +# Outputs to ~/.doc/bash.md +function doc_bash() { + local IFS=$'\n' + local file="${HOME}/.doc/bash.md" + + # Print title. + echo "# Bash reference file." > "${file}" + echo >> "${file}" + + # Print help info. + echo "To get help with usage info run:" >> "${file}" + echo >> "${file}" + echo '```text' >> "${file}" + echo '$ help ' >> "${file}" + echo >> "${file}" + echo "or" >> "${file}" + echo >> "${file}" + echo '$ h ' >> "${file}" + echo '```' >> "${file}" + echo >> "${file}" + + # Print table title. + echo "Command|Description" >> "${file}" + echo "---|---" >> "${file}" + + # Fill with data. + for fun in $(find_functions | sort); do + # Skip private functions. + [[ "${fun}" =~ ^_.* ]] && continue + + # Parse help info. + local desc="$(help ${fun} | grep -v Usage\: | tr '\n' ' ')" + local usage="$(help ${fun} | grep Usage\: | sed -e s\/Usage\:\ \/\/)" + + # Use function name if no usage info available. + [[ "${usage}" = "" ]] && usage="${fun}" + + # Write to file. + [[ "${desc}" != "" ]] && echo "${usage}|${desc}" >> "${file}" + done +} diff --git a/.config/bash/module/docker.sh b/.config/bash/module/docker.sh index 9d0b41d..5544c22 100644 --- a/.config/bash/module/docker.sh +++ b/.config/bash/module/docker.sh @@ -1,4 +1,5 @@ -# show container's volumes. +# Show container's volumes. +# Usage: docker_volumes function docker_volumes() { docker inspect -f '{{ .Mounts }}' "${@}" } @@ -8,43 +9,48 @@ function docker_health() { docker ps -a | grep Exited } -# prune everything. +# Prune everything. function docker_prune() { docker system prune --volumes --all } # Docker compose shortcut. -# Usage: dc [SERVICE] function dc() { docker compose "${@}" } # Docker compose up. +# Usage: dcu [SERVICES] function dcu() { docker compose up -d "${@}" } # Docker compose down. +# Usage: dcd [SERVICES] function dcd() { docker compose down "${@}" } # Docker compose pull. +# Usage: dcp [SERVICES] function dcp() { docker compose pull "${@}" } # Docker compose logs. +# Usage: dcl [SERVICES] function dcl() { docker compose logs -f "${@}" } # Docker compose restart. +# Usage: dcr [SERVICES] function dcr() { docker compose restart "${@}" } # Docker compose stop. +# Usage: dcs [SERVICES] function dcs() { docker compose stop "${@}" } @@ -70,7 +76,7 @@ function dcul() { } # Find out container's IP address. -# Usage: docker_up +# Usage: docker_up function docker_ip() { docker inspect -f '\''{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'\' "${1}" | sed "s/^.//" | sed "s/.$//" } @@ -80,10 +86,12 @@ function docker_update() { docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull } +# Autocomplete with available services. function _dc_services() { _autocomplete "$(docker compose config --services 2> /dev/null)" } +# Autocomplete with available container names. function _dc_containers() { _autocomplete "$(docker ps --format "\""{{.Names}}"\"")" } diff --git a/.config/bash/module/export.sh b/.config/bash/module/export.sh index 2d18926..2e9b0f7 100644 --- a/.config/bash/module/export.sh +++ b/.config/bash/module/export.sh @@ -25,4 +25,4 @@ export TEXMFCONFIG="$HOME/app/tex/data/config" export TEXMFLOCAL="$HOME/app/tex/data/local" # Dotfiles exports. -export DOTFILES_PATH="${HOME}/.config/bash/module" +export BASH_MODULE_PATH="${HOME}/.config/bash/module" diff --git a/.config/bash/module/ffmpeg.sh b/.config/bash/module/ffmpeg.sh index a035680..17455c2 100644 --- a/.config/bash/module/ffmpeg.sh +++ b/.config/bash/module/ffmpeg.sh @@ -1,8 +1,8 @@ -# mux audio into containers. file names in sound and current dirrectories must match. tmp usage for anime downloads. -# usage: ffmpeg_mux_audio +# Mux audio into containers. File names in sound and current dirrectories must match. Tmp usage for anime downloads. +# Usage: ffmpeg_mux_audio function ffmpeg_mux_audio() { - if [[ "$1" = "" ]]; then - echo "usage: ffmpeg_mux_audio " + if [[ "${1}" = "" ]]; then + help ffmpeg_mux_audio return 2 fi @@ -13,7 +13,7 @@ function ffmpeg_mux_audio() { # Usage: ffmpeg_mux_cover function ffmpeg_mux_cover() { if [[ "${1}" = "" ]]; then - echo "Usage: ffmpeg_mux_cover " + help ffmpeg_mux_cover return 2 fi @@ -39,11 +39,14 @@ function ffmpeg_mux_cover() { rm -d out/ && rm "${2}" } -# Change music metadata. +# Generate music metadata from directory structure. +# Top dir is the Artist name like this: The_Beatles. +# Next are albums like this: 2010_My_love. +# Inside are songs like this: 01_sample.flac. # Usage: ffmpeg_music_meta function ffmpeg_music_meta() { if [[ "${1}" = "" ]]; then - echo "Usage: ffmpeg_music_meta " + help ffmpeg_music_meta return 2 fi @@ -71,17 +74,20 @@ function ffmpeg_music_meta() { rm -d out/ } +# Get video FPS. function _ffprobe_fps() { local fps=$(ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate "${1}") fps="${fps%%/*}" echo "${fps}" } +# Get recommended keyframe interval for a file. _ffprobe_keyint() { local fps=$(_ffprobe_fps "${1}") echo $((fps*5)) } +# Get audio bitrage. 128 by default. function _ffprobe_ba() { local ba=$(ffprobe -v error -select_streams a:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "${1}") [[ "${ba}" != "N/A" ]] && echo $((ba/1024)) || echo 128 diff --git a/.config/bash/module/find.sh b/.config/bash/module/find.sh index 2c20125..0805308 100644 --- a/.config/bash/module/find.sh +++ b/.config/bash/module/find.sh @@ -6,5 +6,5 @@ function find_ext() { # Find all module functions. function find_functions() { - cat "${DOTFILES_PATH}"/* | grep "^function.*()" | sed -e "s/^function //" -e "s/().*//" + cat "${BASH_MODULE_PATH}"/* | grep "^function.*()" | sed -e "s/^function //" -e "s/().*//" } diff --git a/.config/bash/module/fix.sh b/.config/bash/module/fix.sh index 0e1bfb5..7f7dbda 100644 --- a/.config/bash/module/fix.sh +++ b/.config/bash/module/fix.sh @@ -1,20 +1,19 @@ -# fix when ethernet mistakenly detects 100 Mb instead of 1000 Mb. -# usage: fix_ethernet_speed +# Fix when ethernet mistakenly detects 100 Mb instead of 1000 Mb. # SPEED is one of 10/100/1000 etc. +# Usage: fix_ethernet_speed function fix_ethernet_speed() { local device="${1}" local speed="${2}" if [[ "${device}" = "" || "${speed}" = "" ]]; then - echo "usage: fix_ethernet_speed " + help fix_ethernet_speed return 2 fi ethtool -s "${device}" speed "${speed}" } -# fix files wrong sftp password. -# alias fix_files_sftp="secret-tool clear protocol sftp server 192.168.1.2" +# Fix nautilus after typing wrong sftp password. function fix_files_sftp() { secret-tool clear protocol sftp } diff --git a/.config/bash/module/git.sh b/.config/bash/module/git.sh index a4d3b31..67c9c5b 100644 --- a/.config/bash/module/git.sh +++ b/.config/bash/module/git.sh @@ -44,6 +44,7 @@ function gch() { } # Git checkout branch. +# Usage: gchb function gchb() { git checkout -b "${@}" } @@ -54,6 +55,7 @@ function gb() { } # Git branch delete. +# Usage: gbd function gbd() { git branch -D "${@}" } @@ -95,7 +97,7 @@ function ggc() { git gc --aggressive --no-cruft --prune=now } -# Preview diff while adding. adds current dir by default. +# Preview diff while adding. Adds current dir by default. # Usage: ga [FILES] function ga() { local target=${@} @@ -108,8 +110,8 @@ function ga() { git add ${target} } -# rebase by X commits or from root. when COUNT is 0 - rebase from root. default is 2. -# usage: gr [COMMIT COUNT] +# Rebase by X commits or from root. When COUNT is 0 - rebase from root. Default is 2. +# Usage: gr [COMMIT COUNT] function gr() { local base="${1}" @@ -126,8 +128,8 @@ function gr() { fi } -# specify git user as Dmitry Voronin with provided email. -# usage: gu [EMAIL] +# Specify git user as Dmitry Voronin with provided email. +# Usage: gu [EMAIL] function gu() { local name="Dmitry Voronin" local email="${1}" @@ -144,7 +146,14 @@ function gu() { # Get my git repo. # Usage: gg function gg() { - git clone https://git.voronind.com/voronind/"${1}" + local repo="${1}" + + if [[ "${repo}" = "" ]]; then + help gg + return 2 + fi + + git clone https://git.voronind.com/voronind/"${repo}" } # See diff for a specific commit. @@ -206,6 +215,7 @@ __git_complete gt _git_tag &> /dev/null __git_complete gp _git_apply &> /dev/null __git_complete ga _git_add &> /dev/null +# Autocomplete with my git emails. function _gu() { _autocomplete_first account@voronind.com dd.voronin@fsight.ru } diff --git a/.config/bash/module/help.sh b/.config/bash/module/help.sh index 9fbb0f7..1bc5ef7 100644 --- a/.config/bash/module/help.sh +++ b/.config/bash/module/help.sh @@ -1,20 +1,23 @@ -# Get help about bash function. +# Get help about dotfiles bash function. +# Usage: help function help() { local fun="${1}" - if [[ $(find_functions | grep "${fun}") = "" ]]; then - echo "Function not found." - return 1 + if [[ "${fun}" = "" ]] || [[ "$(find_functions | grep ${fun})" = "" ]]; then + help help + return 2 fi - sed -e '$s/$/\n/' -s "${DOTFILES_PATH}"/* | sed -n -e "/function ${fun}()/q;p" | tac | sed -n -e "/^$/q;p" | tac | sed -e "s/^# \+//" + sed -e '$s/$/\n/' -s "${BASH_MODULE_PATH}"/* | sed -n -e "/function ${fun}()/q;p" | tac | sed -n -e "/^$/q;p" | tac | sed -e "s/^# \+//" } # Short for help. +# Usage: h function h() { help "${@}" } +# Autocomplete with available functions. function _help_functions() { _autocomplete_first $(find_functions) } diff --git a/.config/bash/module/ls.sh b/.config/bash/module/ls.sh index 92361e6..cd68cb9 100644 --- a/.config/bash/module/ls.sh +++ b/.config/bash/module/ls.sh @@ -1,19 +1,25 @@ -# unset possible system-defined aliases. +# Unset possible system-defined aliases. unalias l ll lll llll la lla &> /dev/null unset l ll lll llll la lla &> /dev/null -# list files in dir. +# List files in dirs. +# Current dir by default. +# Usage: l [DIRS] function l() { - ls -lhv --si --group-directories-first "$@" + ls -lhv --si --group-directories-first -- "$@" } -# list last modified files first. +# List last modified files first. +# Current dir by default. +# Usage: ll [DIRS] function ll() { - ls -lhvtr --si "$@" + ls -lhvtr --si -- "$@" } -# list files in tree structure. -# usage: lll [DEPTH] [DIRS] +# List files in tree structure. +# Current dir by default. +# Depth can be omitted by passing - (dash). +# Usage: lll [DEPTH] [DIRS] function lll() { local IFS=$'\n' local depth="${1}" @@ -26,17 +32,23 @@ function lll() { tree -a -L "${depth}" -- "${target[@]}" } -# list files recursively. +# List files recursively. +# Current dir by default. +# Usage: llll [DIRS] function llll() { - ls -RlAhv --si --group-directories-first "$@" + ls -RlAhv --si --group-directories-first -- "$@" } -# list all files in dir, incl. hidden files. +# List all files in dirs, incl. hidden files. +# Current dir by default. +# Usage: la [DIRS] function la() { - ls -lAh --si --group-directories-first "$@" + ls -lAh --si --group-directories-first -- "$@" } -# list all files in dir, incl. hidden files, sorted by mtime. +# List all files in dirs, incl. hidden files, sorted by mtime. +# Current dir by default. +# Usage: lla [DIRS] function lla() { - ls -lAhtr --si "$@" + ls -lAhtr --si -- "$@" } diff --git a/.config/bash/module/name.sh b/.config/bash/module/name.sh index c2fd94f..b60260d 100644 --- a/.config/bash/module/name.sh +++ b/.config/bash/module/name.sh @@ -1,5 +1,6 @@ -# rename files to strip all special characters. -# usage: name [FILES] +# Rename files to strip all special characters. +# All files by default. +# Usage: name [FILES] function name() { local IFS=$'\n' local targets=("${@}") @@ -62,8 +63,9 @@ function name() { fi } -# rename all files to their hashes while keeping extensions. -# usage: name_hash [FILES] +# Rename all files to their hashes while keeping extensions. +# All files by default. +# Usage: name_hash [FILES] function name_hash() { local IFS=$'\n' local targets=("${@}") @@ -122,13 +124,14 @@ function name_hash() { fi } -# check hashes for renamed files. -# usage: name_hash_check [FILES] +# Check hashes for previously renamed files. +# All files by default. +# Usage: name_hash_check [FILES] function name_hash_check() { local IFS=$'\n' - local targets=("${@}") # target file(s). - local total=${#} # total to process. - local count=0 # processed counter. + local targets=("${@}") + local total=${#} + local count=0 local failed=0 # all targets by default. @@ -164,8 +167,9 @@ function name_hash_check() { fi } -# rename files for Jellyfin series, i.e. Episode S01E01.mkv -# usage: name_series [FILES] +# Rename files for Jellyfin series, i.e. Episode S01E01.mkv +# All files by default. +# Usage: name_series [FILES] function name_series() { local IFS=$'\n' local season="${1}" @@ -218,8 +222,9 @@ function name_series() { fi } -# rename files for Kavita manga format. -# usage: name_manga [FILES] +# Rename files for Kavita manga format. +# All files by default. +# Usage: name_manga [FILES] function name_manga() { local IFS=$'\n' local season="${1}" @@ -273,8 +278,9 @@ function name_manga() { fi } -# rename files for new extension. -# usage: name_ext [FILES] +# Rename files with new extension. +# All files by default. +# Usage: name_ext [FILES] function name_ext() { local IFS=$'\n' local extension="${1}" @@ -325,7 +331,8 @@ function name_ext() { fi } -# Change file prefixes. +# Change file name prefix. +# All matching files by default. # Usage: name_prefix [FILES] function name_prefix() { local IFS=$'\n' @@ -336,7 +343,7 @@ function name_prefix() { local total=$((${#}-2)) local failed=0 - # All targets by default. + # All matching targets by default. if [[ "${targets}" = "" ]]; then targets=(${old}*) total=${#targets[@]} @@ -372,7 +379,8 @@ function name_prefix() { fi } -# Change file postfix. +# Change file name postfix. +# All matching files by default. # Usage: name_postfix [FILES] function name_postfix() { local IFS=$'\n' @@ -383,7 +391,7 @@ function name_postfix() { local total=$((${#}-2)) local failed=0 - # All targets by default. + # All matching targets by default. if [[ "${targets}" = "" ]]; then targets=(*${old}) total=${#targets[@]} @@ -420,6 +428,8 @@ function name_postfix() { } # Replace part of the name. +# All matching files by default. +# Usage: name_replace [FILES] function name_replace() { local IFS=$'\n' local old="${1}" @@ -429,7 +439,7 @@ function name_replace() { local total=$((${#}-2)) local failed=0 - # All targets by default. + # All matching targets by default. if [[ "${targets}" = "" ]]; then targets=(*${old}*) total=${#targets[@]} diff --git a/.config/bash/module/ncdu.sh b/.config/bash/module/ncdu.sh index e2c3289..61940ff 100644 --- a/.config/bash/module/ncdu.sh +++ b/.config/bash/module/ncdu.sh @@ -1,4 +1,6 @@ -# search only on current filesystem. +# Search only on current filesystem. +# Current dir by default. +# Usage: ncdu [DIRS] function ncdu() { - ncdu -x -- "${@}" + /usr/bin/ncdu -x -- "${@}" } diff --git a/.config/bash/module/notify.sh b/.config/bash/module/notify.sh index 7e14967..ca2ab44 100644 --- a/.config/bash/module/notify.sh +++ b/.config/bash/module/notify.sh @@ -1,9 +1,11 @@ -# send Telegram notification. +# Send Telegram notification. +# Usage: notify function notify() { curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null } -# send silent Telegram notification. +# Send silent Telegram notification. +# Usage: notify_silent function notify_silent() { curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\",\"disable_notification\":\"true\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null } diff --git a/.config/bash/module/own.sh b/.config/bash/module/own.sh index 0a427f2..903e27b 100644 --- a/.config/bash/module/own.sh +++ b/.config/bash/module/own.sh @@ -1,5 +1,6 @@ -# change file ownership to specified user id and restrict access to him. -# usage: own [USER] [FILES] +# Change file ownership to specified user id and restrict access to him. +# Root user by default. This directory recursively by default. +# Usage: own [USER] [FILES] function own() { local file="${2}" local user="${1}" diff --git a/.config/bash/module/pack.sh b/.config/bash/module/pack.sh index 8f33e00..f31d05f 100644 --- a/.config/bash/module/pack.sh +++ b/.config/bash/module/pack.sh @@ -1,6 +1,7 @@ -export _UNPACK_SUPPORTED=".tar$|.tgz$|.txz$|.tar.gz$|.tar.xz$|.zip$|.iso$|.rar$" +export _unpack_supported=".tar$|.tgz$|.txz$|.tar.gz$|.tar.xz$|.zip$|.iso$|.rar$" # Pack files into desired format. +# All files and directories by default. # Usage: pack [FILES] function pack() { local IFS=$'\n' @@ -11,20 +12,20 @@ function pack() { # report no output. if [[ "${output}" = "" ]]; then - echo "Usage: pack [FILES]" + help pack return 2 fi # report no format. if [[ "${format}" = "" ]]; then echo "Could not determine output format." - echo "Usage: pack [FILES]" + help pack return 2 fi # All targets by default. if [[ "${targets}" = "" ]]; then - targets=($(ls)) + targets=(*) fi # process. @@ -59,8 +60,9 @@ function pack() { fi } -# attempt to unpack everything. -# usage: unpack [FILES] +# Attempt to unpack. +# All supported formats by default. +# Usage: unpack [FILES] function unpack() { local IFS=$'\n' local targets=("${@}") @@ -70,7 +72,7 @@ function unpack() { # All targets by default. if [[ "${targets}" = "" ]]; then - targets=($(ls | grep -E ${_UNPACK_SUPPORTED})) + targets=($(ls | grep -E ${_unpack_supported})) total=${#targets[@]} fi diff --git a/.config/bash/module/parse.sh b/.config/bash/module/parse.sh index 0550b00..8271648 100644 --- a/.config/bash/module/parse.sh +++ b/.config/bash/module/parse.sh @@ -1,5 +1,5 @@ -# parse data and output simplified format. -# usage: parse_simplify +# Parse data and output simplified format. +# Usage: parse_simplify function parse_simplify() { echo "${*}" | \ sed -e "s/ /_/g" \ @@ -25,8 +25,8 @@ function parse_camel() { echo "${result}" } -# parse data keeping only alphanumeric characters. -# usage: parse_alnum +# Parse data keeping only alphanumeric characters. +# Usage: parse_alnum function parse_alnum() { echo "${*}" | \ sed -e "s/[^[:alnum:]]//g" diff --git a/.config/bash/module/permissions.sh b/.config/bash/module/permissions.sh index 6e2c05d..e91a5da 100644 --- a/.config/bash/module/permissions.sh +++ b/.config/bash/module/permissions.sh @@ -1,9 +1,9 @@ -# recursively change permissions to allow read sharing with group and others. +# Recursively change permissions to allow read sharing with group and others. function perm_share() { find . -type d -exec chmod 755 {} \;; find . -type f -exec chmod 644 {} \; } -# recursively change permissions to restrict access for group and others. +# Recursively change permissions to restrict access for group and others. function perm() { find . -type d -exec chmod 700 {} \;; find . -type f -exec chmod 600 {} \; } diff --git a/.config/bash/module/ps.sh b/.config/bash/module/ps.sh index a9b3ddd..c4e86e5 100644 --- a/.config/bash/module/ps.sh +++ b/.config/bash/module/ps.sh @@ -1,3 +1,12 @@ +# Find process and filter. +# Usage: ps function ps() { - ps aux | grep "${@}" + local process="${1}" + + if [[ "${process}" = "" ]]; then + help ps + return 2 + fi + + /usr/bin/ps aux | sed -n -e "1p" -e "/${process}/Ip" } diff --git a/.config/bash/module/ps1.sh b/.config/bash/module/ps1.sh index b6834f1..e898d35 100644 --- a/.config/bash/module/ps1.sh +++ b/.config/bash/module/ps1.sh @@ -1,6 +1,6 @@ export PROMPT_COMMAND=(__prompt_command "${PROMPT_COMMAND[@]}") -# custom terminal prompt format. +# Custom terminal prompt format. function __prompt_command() { local last_status="${?}" local is_error=false @@ -80,6 +80,8 @@ function __prompt_command() { fi } +# Convert error code into short description. +# Usage: _ps1error function _ps1error() { local type case ${1} in diff --git a/.config/bash/module/recursive.sh b/.config/bash/module/recursive.sh index f2461b2..115fb60 100644 --- a/.config/bash/module/recursive.sh +++ b/.config/bash/module/recursive.sh @@ -1,6 +1,11 @@ # Run something recursively over all directories. # Usage: recursive function recursive() { + if [[ "${*}" = "" ]]; then + help recursive + return 2 + fi + local IFS=$'\n' local current="${PWD}" local dirs=$(find -type d) @@ -20,7 +25,7 @@ function recursive() { echo -e "${color_bblue}[${count}/${total}] ${dir}${color_default}" # run command. - $* || failed=${?} + ${*} || failed=${?} done # return back on complete. @@ -29,10 +34,14 @@ function recursive() { return ${failed} } -# Run something recursively over all directories. +# Run something recursively over directories of 1 depth (excluding current dir). # Usage: recursive1 -# TODO: create generic function. function recursive1() { + if [[ "${*}" = "" ]]; then + help recursive1 + return 2 + fi + local IFS=$'\n' local current="${PWD}" local dirs=$(find -mindepth 1 -maxdepth 1 -type d) @@ -52,7 +61,7 @@ function recursive1() { echo -e "${color_bblue}[${count}/${total}] ${dir}${color_default}" # run command. - $* || failed=${?} + ${*} || failed=${?} done # return back on complete. diff --git a/.config/bash/module/shopt.sh b/.config/bash/module/shopt.sh index 3073793..b375b40 100644 --- a/.config/bash/module/shopt.sh +++ b/.config/bash/module/shopt.sh @@ -1,4 +1,3 @@ -# bash extensions. shopt -s dotglob shopt -s globstar shopt -s autocd diff --git a/.config/bash/module/su.sh b/.config/bash/module/su.sh index 62f3975..f0c18c7 100644 --- a/.config/bash/module/su.sh +++ b/.config/bash/module/su.sh @@ -1,4 +1,6 @@ -# I'm lazy af. +# Su shortcut for lazy me. +# Root by default. +# Usage: s [USER] function s() { - su + su "${@}" } diff --git a/.config/bash/module/terminal.sh b/.config/bash/module/terminal.sh index 5b914f6..e7ddace 100644 --- a/.config/bash/module/terminal.sh +++ b/.config/bash/module/terminal.sh @@ -1,3 +1,4 @@ +# Get terminal size. function tsize() { local width=$(tput cols) local height=$(tput lines) diff --git a/.config/bash/module/tmux.sh b/.config/bash/module/tmux.sh index 78829c8..f23af17 100644 --- a/.config/bash/module/tmux.sh +++ b/.config/bash/module/tmux.sh @@ -1,4 +1,6 @@ -# create/attach to named session. +# Create/attach to named session. +# By default uses name "main". +# Usage: ta [NAME] function ta() { local name="$1" @@ -11,12 +13,12 @@ function ta() { tmux new -s "$name" 2> /dev/null || tmux attach-session -t "$name" } -# detach. +# Detach from running session. function td() { tmux detach-client } -# list. +# List running sessions. function tl() { tmux list-sessions } @@ -31,7 +33,7 @@ function trn() { tmux rename-session "${name}" } -# Assign name (to window). Uses current dir name by default. +# Assign name to window. Uses current dir name by default. # Usage: tn [NAME] function tn() { local name="${1}" @@ -41,7 +43,9 @@ function tn() { tmux rename-window "${name}" } -# kill specified session or default one. +# Kill specified session. +# By default it kills "main" session. +# Usage: tk [NAME] function tk() { # set default name. if [[ "${1}" = "" ]]; then @@ -54,7 +58,7 @@ function tk() { done } -# kill all sessions. +# Kill all sessions. function tka() { local sessions=$(tmux list-sessions | sed -e 's/:.*//') @@ -63,15 +67,17 @@ function tka() { done } -# autocompletes. +# Autocomplete with running sessions once. function _complete_tmux_session() { _autocomplete_first "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')" } +# Autocomplete with running sessions. function _complete_tmux_sessions() { _autocomplete "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')" } +# Autocomplete with current dir name and dirs inside this one. function _complete_tmux_name() { _autocomplete_first "${PWD##*/}"$'\n'$(ls --classify | grep /$ | sed -e 's/\/$//') } diff --git a/.config/bash/module/toolbx.sh b/.config/bash/module/toolbx.sh index 5df9307..c1546be 100644 --- a/.config/bash/module/toolbx.sh +++ b/.config/bash/module/toolbx.sh @@ -1,5 +1,6 @@ -# attach/create toolbx container with default or specified name. -# usage: tb [NAME] +# Attach/create toolbx container with specified name. +# By default uses "main" name. +# Usage: tba [NAME] function tba() { local name="${1}" @@ -36,8 +37,9 @@ function tba() { fi } -# remove toolbx container with default or specified name. -# usage: tbk [NAME] +# Remove toolbx container with specified name. +# By default uses "main" name. +# Usage: tbk [NAME] function tbk() { local name="${1}" @@ -50,8 +52,9 @@ function tbk() { podman stop "${name}" > /dev/null && podman rm "${name}" > /dev/null } -# install rpm-fusion repository. -# usage: tb_rpmfusion [NAME] +# Install rpm-fusion repository into container with specified name. +# By default uses "main" name. +# Usage: tb_rpmfusion [NAME] function tb_rpmfusion() { local name="${1}" @@ -64,12 +67,12 @@ function tb_rpmfusion() { toolbox --container "${name}" run sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm } -# list all containers. +# List all available containers. function tbl() { toolbox list -c } -# autocomplete. +# Autocomplete with available containers. function _tb_containers() { _autocomplete_first "$(toolbox list -c | sed -e '1d' | awk '{ print $2 }')" } diff --git a/.config/bash/module/transcode.sh b/.config/bash/module/transcode.sh index b39be7f..29439e8 100644 --- a/.config/bash/module/transcode.sh +++ b/.config/bash/module/transcode.sh @@ -1,4 +1,5 @@ # Convert between different formats. +# By default tries to convert all files. # Usage: transcode [FILES] function transcode() { local IFS=$'\n' @@ -12,7 +13,7 @@ function transcode() { # Report no format. if [[ "${format}" = "" ]]; then echo -e "${color_bred}No format specified.${color_default}" - echo "Usage: transcode [FILES]" + help transcode return 2 fi diff --git a/.config/bash/module/try.sh b/.config/bash/module/try.sh index 8bb1a06..a8714e3 100644 --- a/.config/bash/module/try.sh +++ b/.config/bash/module/try.sh @@ -1,9 +1,15 @@ -# retry command every 2 sec until it completes. +# Retry command every 2 sec until it completes successfully. +# Usage: try function try() { + if [[ "${*}" = "" ]]; then + help try + return 2 + fi + local result=-1 while [ "$result" != 0 ]; do - $@ + ${*} result=$? if [ "$result" != 0 ]; then sleep 2 diff --git a/.config/bash/module/umask.sh b/.config/bash/module/umask.sh index 388f8c3..08b18ee 100644 --- a/.config/bash/module/umask.sh +++ b/.config/bash/module/umask.sh @@ -1,2 +1 @@ -# set global umask. umask 077 diff --git a/.config/bash/module/vdl.sh b/.config/bash/module/vdl.sh index ef5fc7c..694f810 100644 --- a/.config/bash/module/vdl.sh +++ b/.config/bash/module/vdl.sh @@ -1,4 +1,4 @@ -# Download video from URL in background. When no [LINK] specified, it tries to update previously downloaded link. +# Download video from URL. When no [LINK] specified, it tries to update previously downloaded link. # Usage: vdl [LINK] function vdl() { # Check that ffmpeg and ffprobe are available. @@ -10,12 +10,12 @@ function vdl() { local target="${@}" # What to download/update. # If no [LINK] provided, try to read from `src.txt`. - [[ "${target}" = "" ]] && target="$(cat src.txt)" + [[ "${target}" = "" ]] && target="$(cat src.txt)" # If could not get [LINK] eventually, show an error and exit. if [[ "${target}" = "" ]]; then echo -e "${color_red}Could not determine [LINK] to download.${color_default}" - echo "Usage: vdl [LINK]" + help vdl return 2 fi @@ -26,20 +26,14 @@ function vdl() { yt-dlp -f 'bestvideo[height<=?1081]+bestaudio/best' --download-archive index.txt --embed-thumbnail --embed-subs --write-auto-subs --embed-metadata --merge-output-format mkv -cio '%(playlist_index)000006d_%(id)s.%(ext)s' ${target} # || _vdl_retry } +# Temporary fix for vk downloads. +# Usage: vdl_vk function vdl_vk() { vdl --format mp4 "${@}" } -# Temporary fix for crashes. -function _vdl_retry() { - for file in *.part; do - local number="${file%%_*}" - rm ${number}* - done - vdl -} - -# download all videos from file. +# Download all videos from file with links. +# Usage: vdl_file function vdl_file() { vdl -a "${@}" } diff --git a/.config/bash/module/vi.sh b/.config/bash/module/vi.sh index 78ecedc..a7e7d84 100644 --- a/.config/bash/module/vi.sh +++ b/.config/bash/module/vi.sh @@ -1,9 +1,4 @@ -# default vim. -function vi() { - vi -c "filetype plugin indent on" -c "set autoindent" -c "set tabstop=2" -c "set shiftwidth=2" -c "set expandtab" -c "set number" -- "${@}" -} - -# neovim. +# Neovim shortcut. function v() { nvim -- "${@}" } diff --git a/.config/bash/module/wallpaper.sh b/.config/bash/module/wallpaper.sh index 84a20fd..f2cb2bc 100644 --- a/.config/bash/module/wallpaper.sh +++ b/.config/bash/module/wallpaper.sh @@ -1,6 +1,14 @@ -# set specified file as a wallpaper. +# Set specified file as a wallpaper. +# Usage: wallpaper function wallpaper() { - path_wallpaper=~/.local/share/backgrounds/background.jpg - cp "$1" $path_wallpaper - chmod 644 $path_wallpaper + local target="${1}" + local path_wallpaper=~/.local/share/backgrounds/background.jpg + + if [[ "${target}" = "" ]]; then + help wallpaper + return 2 + fi + + cp "${target}" "${path_wallpaper}" + chmod 644 "${path_wallpaper}" } diff --git a/.config/bash/module/watch.sh b/.config/bash/module/watch.sh index 4d18ccb..133a23f 100644 --- a/.config/bash/module/watch.sh +++ b/.config/bash/module/watch.sh @@ -1,12 +1,22 @@ # Watch command output with 2 second interval. # Usage: w function w() { + if [[ "${*}" = "" ]]; then + help w + return 2 + fi + watch -n 2 "${@}" } # Watch command output with minimal interval. # Usage: ww function ww() { + if [[ "${*}" = "" ]]; then + help ww + return 2 + fi + watch -n 0 "${@}" }