⚡ refacts bash/profile setup
This commit is contained in:
41
.bash/toolchains/README.md
Normal file
41
.bash/toolchains/README.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# Toolchain Configuration
|
||||
|
||||
Development tool configurations including aliases and environment managers.
|
||||
|
||||
## Files
|
||||
|
||||
- `index.sh` - Main entry point
|
||||
- `aliases.sh` - Comprehensive aliases collection (grouped by functionality)
|
||||
- `brew.sh` - Homebrew setup
|
||||
- `cross-session/` - Cross-session variable management system:
|
||||
- `index.sh` - Entry point
|
||||
- `store.sh` - Storage for cross-session variables
|
||||
- `jaaenv.sh` - Custom environment management (Java, Node.js, PHP, Gradle)
|
||||
- `nvm-node.sh` - Node/nvm setup
|
||||
- `portkiller/` - Port killer utility (git submodule)
|
||||
- `sdkman.sh` - SDKMAN setup
|
||||
- `tv.sh` - television (completition) setup
|
||||
- `vifm.sh` - VIFM replaced via this
|
||||
|
||||
## Organization
|
||||
|
||||
- **Color/UX settings**: Located in `shell/ux.sh`
|
||||
- **Cross-session management**: Now in `cross-session/` subdirectory
|
||||
- **Aliases**: Grouped in `aliases.sh` by functionality:
|
||||
- System aliases (ls, grep, etc.)
|
||||
- Git and version control
|
||||
- Utility functions
|
||||
- Network utilities
|
||||
- Node.js tools
|
||||
- RPG utilities
|
||||
- Process management
|
||||
- **Environment management**: Split across specialized files:
|
||||
- `jaaenv.sh` - Main environment system
|
||||
- `nvm-node.sh` - Node.js version management
|
||||
- `sdkman.sh` - SDKMAN management
|
||||
|
||||
## Important Notes
|
||||
|
||||
- Contains development tools and shortcuts
|
||||
- Environment managers handle Java, Node.js, PHP, Gradle versions
|
||||
- Automatically sourced by main `.bashrc`
|
||||
126
.bash/toolchains/aliases.sh
Normal file
126
.bash/toolchains/aliases.sh
Normal file
@@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env bash
|
||||
export PATH="$PATH:$HOME/.local/share/soar/bin"
|
||||
|
||||
cd() {
|
||||
builtin cd "$@" || return $?
|
||||
crossSession 'OLDPWD' "$(pwd)"
|
||||
local -r hook="$BASH_DOTFILES/hooks/oncd"
|
||||
[[ -f "$hook" ]] && source "$hook"
|
||||
}
|
||||
|
||||
alias gitdotfiles='/usr/bin/git --git-dir="$HOME/.dotfiles/" --work-tree="$HOME"'
|
||||
|
||||
alias §df='df -Th'
|
||||
|
||||
git(){
|
||||
if [[ -z "$1" ]]; then
|
||||
git-i
|
||||
return 0
|
||||
fi
|
||||
command git "$@"
|
||||
}
|
||||
alias smerge='/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=sublime_merge --file-forwarding com.sublimemerge.App @@u %u @@'
|
||||
kommit(){
|
||||
if flatpak info org.kde.kommit > /dev/null 2>&1; then
|
||||
flatpak run \
|
||||
--branch=stable --arch=x86_64 \
|
||||
--file-forwarding \
|
||||
--command=kommit org.kde.kommit @@u $* @@ > /dev/null 2>&1 & disown;
|
||||
else
|
||||
command kommit $* > /dev/null 2>&1 & disown;
|
||||
fi
|
||||
}
|
||||
export SVN_CONFIG_DIR="$HOME/.config/subversion"
|
||||
alias svn='svn --config-dir "$SVN_CONFIG_DIR"'
|
||||
|
||||
§(){
|
||||
[[ -z "$1" ]] && clear && return 0
|
||||
echo "$ [--help]= clear or [print this text]"
|
||||
alias | grep "alias §" --color=never
|
||||
declare -F | grep 'declare -f §' --color=never
|
||||
\ls ~/.local/bin | grep -P "^§" | xargs -I{} echo '~/.local/bin/'{}
|
||||
printenv | grep -e '^l' | xargs -I{} echo \${}
|
||||
}
|
||||
|
||||
bw-session(){
|
||||
bw logout
|
||||
login=$(§kwallet.mjs --wallet kdewallet readPassword accounts bw-json)
|
||||
export BW_CLIENTSECRET=`echo "$login" | jq -r .secret`
|
||||
export BW_CLIENTID=`echo "$login" | jq -r .id`
|
||||
bw login --apikey --raw
|
||||
export BW_SESSION=`bw unlock --raw $(echo "$login" | jq -r .pass)` && echo "Bitwarden session ON" || echo "Bitwarden session FAILED"
|
||||
unset BW_CLIENTSECRET
|
||||
unset BW_CLIENTID
|
||||
}
|
||||
|
||||
alias §ps-mem='ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem'
|
||||
alias §ps-cpu='ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu'
|
||||
alias §lsoft-all='lsoft -P -i -n'
|
||||
§ping-test() {
|
||||
ping -c 1 -q 8.23.224.107 | grep --color=never -A 1 -i '\---'
|
||||
ping -c 1 -q www.google.com | grep --color=never -A 1 -i '\---'
|
||||
}
|
||||
§whoami(){
|
||||
[[ "$1" == '--help' ]] && echo '§whoami; §whoami --ip' && return 0
|
||||
local ip=$(curl -s ifconfig.me)
|
||||
[[ "$1" == '--ip' ]] && echo "$ip" && return 0
|
||||
local L="\t%s\n"
|
||||
printf "\n"
|
||||
printf "$L" "USER: $(echo $USER)"
|
||||
printf "$L" "IP ADDR: $ip"
|
||||
printf "$L" "HOSTNAME: $(hostname -f)"
|
||||
printf "$L" "KERNEL: $(uname -rms)"
|
||||
printf "\n"
|
||||
}
|
||||
§curl-location() { curl --silent -I "$1" | grep -i location; }
|
||||
§interfaces() {
|
||||
node <<-JAVASCRIPT
|
||||
var os = require('os');
|
||||
var i = os.networkInterfaces();
|
||||
Object.keys(i).forEach(function(name) {
|
||||
i[name].forEach(function(int) {
|
||||
if (int.family === 'IPv4') {
|
||||
console.log('%s: %s', name, int.address);
|
||||
}
|
||||
});
|
||||
});
|
||||
JAVASCRIPT
|
||||
}
|
||||
§speedtest() {
|
||||
curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python3 -
|
||||
}
|
||||
portkiller(){
|
||||
"$BASH_DOTFILES/portkiller/portkiller.sh" $*
|
||||
}
|
||||
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
|
||||
|
||||
§cmdfu() { curl "https://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext"; }
|
||||
|
||||
alias npx-wca='npx -y web-component-analyzer'
|
||||
alias npx-qnm='npx -y qnm'
|
||||
alias npx-hint='npx -y hint'
|
||||
alias npx-markdown='npx -y markserv'
|
||||
alias npx-toon='npx -y @toon-format/cli'
|
||||
|
||||
rpg(){
|
||||
rpg-cli "$@"
|
||||
if ( [[ "$1" == "cd" ]] || [[ "$1" == "ls" ]] ); then
|
||||
[[ "$2" == "" ]] && $1 . && return 0
|
||||
[[ "$2" == ".." ]] && $1 .. && return 0
|
||||
[[ "-1" != "$(nodejsscript --print "s.ls().findIndex(e=> e==='$2'.replace(/\/$/, ''))")" ]] && $1 "$2" && return 0
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
rpg-dungeon(){
|
||||
current=$(basename $PWD)
|
||||
number_re='^[0-9]+$'
|
||||
|
||||
if [[ $current =~ $number_re ]]; then
|
||||
next=$(($current + 1))
|
||||
command mkdir -p $next && cd $next && rpg ls
|
||||
elif [[ -d 1 ]] ; then
|
||||
cd 1 && rpg ls
|
||||
else
|
||||
command mkdir -p dungeon/1 && cd dungeon/1 && rpg ls
|
||||
fi
|
||||
}
|
||||
18
.bash/toolchains/brew.sh
Executable file
18
.bash/toolchains/brew.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
|
||||
|
||||
[[ "$-" != *i* ]] && return
|
||||
|
||||
if type brew &>/dev/null
|
||||
then
|
||||
HOMEBREW_PREFIX="$(brew --prefix)"
|
||||
if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]
|
||||
then
|
||||
PS1='force' source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
|
||||
else
|
||||
for COMPLETION in "${HOMEBREW_PREFIX}/etc/bash_completion.d/"*
|
||||
do
|
||||
[[ -r "${COMPLETION}" ]] && source "${COMPLETION}"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
39
.bash/toolchains/cross-session/index.sh
Normal file
39
.bash/toolchains/cross-session/index.sh
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
declare -r CROSS_SESSION="$BASH_DOTFILES/toolchains/cross-session/store.sh"
|
||||
[[ -f "$CROSS_SESSION" ]] && \
|
||||
source "$CROSS_SESSION"
|
||||
|
||||
# Cross session management function
|
||||
crossSession() {
|
||||
if [[ '--help' == "${1:---help}" ]]; then
|
||||
echo 'crossSession [--help]'
|
||||
echo ' Print this help.'
|
||||
echo 'crossSession [--list]'
|
||||
echo ' Lists all cross session variables or print this help.'
|
||||
echo 'crossSession <name> [<value>]'
|
||||
echo ' Sets cross session variable <name> to <value> (or empty for unset).'
|
||||
return 0
|
||||
fi
|
||||
if [[ '--list' == "$1" ]]; then
|
||||
cat "$CROSS_SESSION"
|
||||
return 0
|
||||
fi
|
||||
local name="$1"
|
||||
local value="$2"
|
||||
|
||||
# Check if the variable already exists in the file
|
||||
if grep -q "^export $name=" "$CROSS_SESSION"; then
|
||||
if [[ -z "$value" ]]; then
|
||||
# If new value is empty, remove the variable from the file
|
||||
sed -i "/^export $name=/d" "$CROSS_SESSION"
|
||||
else
|
||||
# If it exists, replace the old value with the new value
|
||||
sed -i "s|^export $name=.*|export $name=\"$value\"|" "$CROSS_SESSION"
|
||||
fi
|
||||
else
|
||||
if [[ -n "$value" ]]; then
|
||||
# If it doesn't exist and new value is not empty, append the new variable to the file
|
||||
echo "export $name='$value'" >> "$CROSS_SESSION"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
9
.bash/toolchains/cross-session/store.sh
Normal file
9
.bash/toolchains/cross-session/store.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
# vim: filetype=bash
|
||||
export OLDPWD="/home/jaandrle/Vzdálené/GitHub/facilitator-network-cell"
|
||||
export mwdcp='/home/jaandrle/Vzdálené/GitHub/dcp-fe-container-certifedpassport'
|
||||
export mdde='/home/jaandrle/Vzdálené/GitHub/deka-dom-el'
|
||||
export mwdgf='/home/jaandrle/Vzdálené/GitHub/DGF-Certified-Supervisory-Academy'
|
||||
export mwdgfapi='/home/jaandrle/Vzdálené/GitHub/DGF-Certified-Supervisory-Academy-API'
|
||||
export mkde='/home/jaandrle/Dokumenty/Projekty/kde-překlady'
|
||||
export mwnetcell='/home/jaandrle/Vzdálené/GitHub/facilitator-network-cell'
|
||||
export mb='/home/jaandrle/.bash'
|
||||
13
.bash/toolchains/index.sh
Normal file
13
.bash/toolchains/index.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
# Toolchains configuration index
|
||||
# Source all toolchain-related configuration files
|
||||
|
||||
declare dir="$BASH_DOTFILES/toolchains"
|
||||
|
||||
source "$dir/cross-session/index.sh"
|
||||
|
||||
for file in "$dir"/*.sh; do
|
||||
[[ -f "$file" && "$file" != "$dir/index.sh" ]] && source "$file"
|
||||
done
|
||||
|
||||
unset dir
|
||||
179
.bash/toolchains/jaaenv.sh
Normal file
179
.bash/toolchains/jaaenv.sh
Normal file
@@ -0,0 +1,179 @@
|
||||
#!/usr/bin/env bash
|
||||
# jaaENV - Environment management system
|
||||
function jaaENV {
|
||||
if [[ "$1" = "--help" ]]; then
|
||||
echo "jaaENV - Environment Management System"
|
||||
echo "Utility to manage multiple tool versions in one config file '.jaaENV'"
|
||||
echo "Replaces: 'nvm use 16 && sdk use java 11 && ...'"
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo " jaaENV # Load settings from .jaaENV or compose.yaml"
|
||||
echo " jaaENV --help # Show this help"
|
||||
echo " jaaENV --ls # List available versions (nvm, sdk, php, java)"
|
||||
echo " jaaENV --save nodejs php # Save current versions to .jaaENV"
|
||||
echo ""
|
||||
echo "Example .jaaENV file:"
|
||||
echo " nodejs=16.13.0"
|
||||
echo " php=8.1"
|
||||
echo " java=11"
|
||||
echo " gradle=7.4"
|
||||
echo ""
|
||||
echo "Supported options:"
|
||||
echo " android_home # Use ANDROID_HOME instead of ANDROID_SDK_ROOT"
|
||||
echo " jdk # Set JAVA_HOME for Android Studio (9+)"
|
||||
echo " nodejs|php # Node.js/PHP version management"
|
||||
echo " java # Java version switching"
|
||||
echo " gradle # Gradle version management"
|
||||
echo ""
|
||||
echo "Requirements:"
|
||||
echo " NVM: https://github.com/nvm-sh/nvm (Node.js)"
|
||||
echo " SDKMAN: https://sdkman.io (Java, Gradle, etc.)"
|
||||
echo " PHP: update-alternatives + https://deb.sury.org/"
|
||||
echo " Java: update-alternatives"
|
||||
echo ""
|
||||
echo "Quick setup:"
|
||||
echo " sudo update-alternatives --set php /usr/bin/php8.1"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "$1" == "--save" ]]; then
|
||||
shift
|
||||
rm -vi .jaaENV
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
nodejs|node)
|
||||
echo "nodejs=$(node --version | cut -c2-)" >> .jaaENV
|
||||
;;
|
||||
gradle)
|
||||
echo "gradle=$(gradle --version | awk '/Gradle/ {print $2}')" >> .jaaENV
|
||||
;;
|
||||
php)
|
||||
echo "php=$(php --version | awk '/^PHP/ {print $2}')" >> .jaaENV
|
||||
;;
|
||||
java)
|
||||
local java_version
|
||||
java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}')
|
||||
if [[ "$java_version" == 1.8* ]]; then
|
||||
java_version="8"
|
||||
else
|
||||
java_version=$(echo "$java_version" | cut -d'.' -f1)
|
||||
fi
|
||||
echo "java=$java_version" >> .jaaENV
|
||||
;;
|
||||
*)
|
||||
echo "Unknown '$1' – skipped"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "$1" == "--ls" ]]; then
|
||||
echo ":: nvm ls --no-alias ::"
|
||||
nvm ls --no-alias
|
||||
echo ":: update-alternatives --list php ::"
|
||||
update-alternatives --list php
|
||||
echo ":: update-alternatives --list java ::"
|
||||
update-alternatives --list java
|
||||
echo ":: sdk ls gradle | grep -E '\*|>' ::"
|
||||
sdk ls gradle | grep -E '\*|>'
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -f "compose.yaml" ]]; then
|
||||
jdk=$(grep -Po 'VERSION_JAVA=\K.*' compose.yaml)
|
||||
nodejs=$(grep -Po 'VERSION_NODEJS=\K.*' compose.yaml)
|
||||
elif [[ -f ".jaaENV" ]]; then
|
||||
source ./.jaaENV
|
||||
else
|
||||
echo 'No env file `compose.yaml` or `.jaaENV`'
|
||||
return 1
|
||||
fi
|
||||
|
||||
local chP="\[\033[0;35m\]" #purple
|
||||
local chW="\[\033[00m\]" #white
|
||||
export PS1_jaaENV="${chP}¦${chW}"
|
||||
|
||||
if [[ -n "${ANDROID_SDK_ROOT_BAK+x}" ]]; then
|
||||
export ANDROID_SDK_ROOT="$ANDROID_SDK_ROOT_BAK"
|
||||
echo "\$ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT_BAK"
|
||||
unset ANDROID_SDK_ROOT_BAK
|
||||
fi
|
||||
if [[ -n "${unset_android_sdk+x}" ]]; then
|
||||
export ANDROID_SDK_ROOT_BAK="$ANDROID_SDK_ROOT"
|
||||
unset ANDROID_SDK_ROOT
|
||||
fi
|
||||
if [[ -n "${java+x}" ]]; then
|
||||
if [[ "$java" == "8" ]]; then
|
||||
java="1.8"
|
||||
fi
|
||||
local java_local
|
||||
java_local=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}')
|
||||
if [[ "$java_local" != "$java"* ]]; then
|
||||
if [[ "$java" == "1.8" ]]; then
|
||||
java="8"
|
||||
fi
|
||||
echo "Switching Java version: $java ← $java_local"
|
||||
local java_path="/usr/lib/jvm/java-$java-openjdk-amd64/"
|
||||
if [[ "$java" == "8" ]]; then
|
||||
java_path+="jre/"
|
||||
fi
|
||||
sudo update-alternatives --set java "${java_path}bin/java"
|
||||
local javac
|
||||
javac=$(update-alternatives --list javac | grep "java-$java")
|
||||
if [[ -n "$javac" ]]; then
|
||||
sudo update-alternatives --set javac "$javac"
|
||||
fi
|
||||
sudo -k
|
||||
fi
|
||||
export JAVA_HOME=$(readlink -f "$(which java)" | cut -d '/' -f1-5)/
|
||||
echo "\$JAVA_HOME=$JAVA_HOME"
|
||||
fi
|
||||
if [[ -n "${android_home+x}" ]]; then
|
||||
export ANDROID_HOME="$ANDROID_HOME_BAK"
|
||||
echo "\$ANDROID_HOME=$ANDROID_HOME"
|
||||
else
|
||||
unset ANDROID_HOME
|
||||
echo "\$ANDROID_SDK_ROOT=$ANDROID_SDK_ROOT"
|
||||
fi
|
||||
if [[ -n "${android_home_is_sdk+x}" ]]; then
|
||||
export ANDROID_HOME="$ANDROID_SDK_ROOT"
|
||||
echo "\$ANDROID_HOME=$ANDROID_HOME"
|
||||
fi
|
||||
if [[ -n "${JAVA_HOME_BAK+x}" ]]; then
|
||||
export JAVA_HOME="$JAVA_HOME_BAK"
|
||||
unset JAVA_HOME_BAK
|
||||
fi
|
||||
if [[ -n "${jdk+x}" ]]; then
|
||||
if (( $(echo "$jdk > 9" | bc -l) )); then
|
||||
export JAVA_HOME_BAK="$JAVA_HOME"
|
||||
export JAVA_HOME="/snap/android-studio/current/android-studio/jre"
|
||||
fi
|
||||
echo "\$JAVA_HOME=$JAVA_HOME"
|
||||
fi
|
||||
if [[ -n "${nodejs+x}" ]]; then
|
||||
if [[ "$(which node)" == *linuxbrew* ]]; then
|
||||
brew unlink node
|
||||
fi
|
||||
nvm use "$nodejs"
|
||||
fi
|
||||
if [[ -n "${gradle+x}" ]]; then
|
||||
sdk use gradle "$gradle" | tr -d '\n'
|
||||
echo
|
||||
fi
|
||||
if [[ -n "${php+x}" ]]; then
|
||||
local php_local
|
||||
php_local=$(php --version | awk '/^PHP/ {print $2}')
|
||||
if [[ "$php_local" == "$php"* ]]; then
|
||||
echo "PHP version: $php"
|
||||
else
|
||||
echo "Switching PHP version: $php ← $php_local"
|
||||
sudo update-alternatives --set php "/usr/bin/php$php"
|
||||
sudo -k
|
||||
fi
|
||||
fi
|
||||
|
||||
# Cleanup variables
|
||||
unset android_home unset_android_sdk nodejs gradle php java
|
||||
}
|
||||
7
.bash/toolchains/nvm-node.sh
Normal file
7
.bash/toolchains/nvm-node.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
eval "$([[ -s "$NVM_DIR/nvm.sh" ]] && echo "source '$NVM_DIR/nvm.sh'")"
|
||||
eval "$([[ -s "$NVM_DIR/bash_completion" ]] && echo "source '$NVM_DIR/bash_completion'")"
|
||||
|
||||
export NODE_COMPILE_CACHE="$HOME/.cache/nodejs-compile-cache" # https://nolanlawson.com/2024/10/20/why-im-skeptical-of-rewriting-javascript-tools-in-faster-languages/
|
||||
1
.bash/toolchains/portkiller
Submodule
1
.bash/toolchains/portkiller
Submodule
Submodule .bash/toolchains/portkiller added at cab2f17072
7
.bash/toolchains/sdkman.sh
Normal file
7
.bash/toolchains/sdkman.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# SDKMAN! - Software Development Kit Manager
|
||||
|
||||
export SDKMAN_DIR="$HOME/.sdkman"
|
||||
[[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] && source "$SDKMAN_DIR/bin/sdkman-init.sh"
|
||||
|
||||
# Usage: sdk install java 11.0.12-open, sdk use java 11.0.12-open
|
||||
462
.bash/toolchains/tv.sh
Normal file
462
.bash/toolchains/tv.sh
Normal file
@@ -0,0 +1,462 @@
|
||||
#!/usr/bin/env bash
|
||||
[[ "$-" != *i* ]] && return
|
||||
|
||||
_tv() {
|
||||
local i cur prev opts cmd
|
||||
COMPREPLY=()
|
||||
if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then
|
||||
cur="$2"
|
||||
else
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
fi
|
||||
prev="$3"
|
||||
cmd=""
|
||||
opts=""
|
||||
|
||||
for i in "${COMP_WORDS[@]:0:COMP_CWORD}"
|
||||
do
|
||||
case "${cmd},${i}" in
|
||||
",$1")
|
||||
cmd="tv"
|
||||
;;
|
||||
tv,help)
|
||||
cmd="tv__help"
|
||||
;;
|
||||
tv,init)
|
||||
cmd="tv__init"
|
||||
;;
|
||||
tv,list-channels)
|
||||
cmd="tv__list__channels"
|
||||
;;
|
||||
tv,update-channels)
|
||||
cmd="tv__update__channels"
|
||||
;;
|
||||
tv__help,help)
|
||||
cmd="tv__help__help"
|
||||
;;
|
||||
tv__help,init)
|
||||
cmd="tv__help__init"
|
||||
;;
|
||||
tv__help,list-channels)
|
||||
cmd="tv__help__list__channels"
|
||||
;;
|
||||
tv__help,update-channels)
|
||||
cmd="tv__help__update__channels"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
case "${cmd}" in
|
||||
tv)
|
||||
opts="$(tv list-channels) [CHANNEL] -s -p -i -t -k -h -V --source-command --ansi --no-sort --source-display --source-output --source-entry-delimiter --preview-command --preview-header --preview-footer --cache-preview --preview-offset --no-preview --hide-preview --show-preview --preview-border --preview-padding --preview-word-wrap --hide-preview-scrollbar --preview-size --input --input-header --input-prompt --input-position --input-border --input-padding --no-status-bar --hide-status-bar --show-status-bar --results-border --results-padding --layout --no-remote --hide-remote --show-remote --no-help-panel --hide-help-panel --show-help-panel --ui-scale --height --width --inline --tick-rate --watch --autocomplete-prompt --exact --select-1 --take-1 --take-1-fast --keybindings --expect --config-file --cable-dir --global-history --help --version [PATH] list-channels init update-channels help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
--source-command)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-s)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--source-display)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--source-output)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--source-entry-delimiter)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--preview-command)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-p)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--preview-header)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--preview-footer)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--preview-offset)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--preview-border)
|
||||
COMPREPLY=($(compgen -W "none plain rounded thick" -- "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--preview-padding)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--preview-size)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--input)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-i)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--input-header)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--input-prompt)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--input-position)
|
||||
COMPREPLY=($(compgen -W "top bottom" -- "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--input-border)
|
||||
COMPREPLY=($(compgen -W "none plain rounded thick" -- "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--input-padding)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--results-border)
|
||||
COMPREPLY=($(compgen -W "none plain rounded thick" -- "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--results-padding)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--layout)
|
||||
COMPREPLY=($(compgen -W "landscape portrait" -- "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--ui-scale)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--height)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--width)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--tick-rate)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-t)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--watch)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--autocomplete-prompt)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--keybindings)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-k)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--expect)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--config-file)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--cable-dir)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
tv__help)
|
||||
opts="list-channels init update-channels help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
tv__help__help)
|
||||
opts=""
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
tv__help__init)
|
||||
opts=""
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
tv__help__list__channels)
|
||||
opts=""
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
tv__help__update__channels)
|
||||
opts=""
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
tv__init)
|
||||
opts="-h --help bash zsh fish power-shell cmd nu"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
tv__list__channels)
|
||||
opts="-h --help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
tv__update__channels)
|
||||
opts="-h --force --help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
|
||||
complete -F _tv -o nosort -o bashdefault -o default tv
|
||||
else
|
||||
complete -F _tv -o bashdefault -o default tv
|
||||
fi
|
||||
_disable_bracketed_paste() {
|
||||
# Disable bracketed paste mode to prevent unwanted escape sequences
|
||||
printf '\e[?2004l' > /dev/tty
|
||||
}
|
||||
|
||||
_enable_bracketed_paste() {
|
||||
# Re-enable bracketed paste mode
|
||||
printf '\e[?2004h' > /dev/tty
|
||||
}
|
||||
|
||||
__tv_path_completion() {
|
||||
local base="$1"
|
||||
local lbuf="$2"
|
||||
local suffix=""
|
||||
local tail=" "
|
||||
local dir leftover matches
|
||||
|
||||
# Evaluate the base path (handle ~, variables, etc.)
|
||||
eval "base=\"$base\"" 2>/dev/null || return
|
||||
|
||||
# Extract directory part if base contains a slash
|
||||
[[ "$base" == *"/"* ]] && dir="$base"
|
||||
|
||||
while true; do
|
||||
if [[ -z "$dir" || -d "$dir" ]]; then
|
||||
# Calculate leftover part (what comes after the directory)
|
||||
leftover="${base#"$dir"}"
|
||||
leftover="${leftover#/}"
|
||||
|
||||
# Set default directory if empty
|
||||
[[ -z "$dir" ]] && dir='.'
|
||||
|
||||
# Remove trailing slash unless it's root
|
||||
[[ "$dir" != "/" ]] && dir="${dir%/}"
|
||||
|
||||
# move to the next line so that the prompt is not overwritten
|
||||
printf "\n"
|
||||
|
||||
# Call tv with proper arguments and process output
|
||||
matches=$(
|
||||
tv "$dir" --autocomplete-prompt "$lbuf" --no-status-bar --inline --input "$leftover" < /dev/tty | while IFS= read -r item; do
|
||||
item="${item%$suffix}$suffix"
|
||||
dirP="$dir/"
|
||||
[[ "$dirP" == "./" ]] && dirP=""
|
||||
# Quote the item to handle special characters
|
||||
printf '%s ' "$dirP$(printf '%q' "$item")"
|
||||
done
|
||||
)
|
||||
|
||||
# Remove trailing space
|
||||
matches="${matches% }"
|
||||
|
||||
if [[ -n "$matches" ]]; then
|
||||
# Update readline buffer
|
||||
local new_line="$lbuf$matches$tail"
|
||||
local rhs="${READLINE_LINE:$READLINE_POINT}"
|
||||
READLINE_LINE="$new_line$rhs"
|
||||
READLINE_POINT=${#new_line}
|
||||
fi
|
||||
# move the cursor back to the previous line
|
||||
printf "\033[A"
|
||||
|
||||
break
|
||||
fi
|
||||
|
||||
# Move up one directory level
|
||||
dir=$(dirname "$dir")
|
||||
dir="${dir%/}/"
|
||||
done
|
||||
}
|
||||
|
||||
tv_smart_autocomplete() {
|
||||
_disable_bracketed_paste
|
||||
|
||||
local tokens prefix lbuf
|
||||
local current_prompt="${READLINE_LINE:0:$READLINE_POINT}"
|
||||
|
||||
# Split the current prompt into tokens
|
||||
# This is a simplified version of zsh's word splitting
|
||||
read -ra tokens <<< "$current_prompt"
|
||||
|
||||
if [[ ${#tokens[@]} -lt 1 ]]; then
|
||||
# Fall back to default completion if no tokens
|
||||
_enable_bracketed_paste
|
||||
return
|
||||
fi
|
||||
|
||||
# Handle trailing space
|
||||
[[ "${READLINE_LINE:$((READLINE_POINT-1)):1}" == " " ]] && tokens+=("")
|
||||
|
||||
# Get the last token as prefix
|
||||
prefix="${tokens[-1]}"
|
||||
|
||||
# Calculate lbuf (everything except the last token)
|
||||
if [[ -n "$prefix" ]]; then
|
||||
lbuf="${current_prompt:0:$((${#current_prompt} - ${#prefix}))}"
|
||||
else
|
||||
lbuf="$current_prompt"
|
||||
fi
|
||||
|
||||
__tv_path_completion "$prefix" "$lbuf"
|
||||
|
||||
_enable_bracketed_paste
|
||||
}
|
||||
|
||||
tv_shell_history() {
|
||||
_disable_bracketed_paste
|
||||
|
||||
local current_prompt="${READLINE_LINE:0:$READLINE_POINT}"
|
||||
local output
|
||||
|
||||
# move to the next line so that the prompt is not overwritten
|
||||
printf "\n"
|
||||
|
||||
# Get history using tv with the same arguments as zsh version
|
||||
output=$(tv bash-history --no-status-bar --input "$current_prompt" --inline)
|
||||
|
||||
if [[ -n "$output" ]]; then
|
||||
# Clear the right side of cursor and set new line
|
||||
READLINE_LINE="$output"
|
||||
READLINE_POINT=${#READLINE_LINE}
|
||||
|
||||
# Uncomment this to automatically accept the line
|
||||
# (i.e. run the command without having to press enter twice)
|
||||
# accept-line() { echo; }; accept-line
|
||||
fi
|
||||
|
||||
# move the cursor back to the previous line
|
||||
printf "\033[A"
|
||||
|
||||
_enable_bracketed_paste
|
||||
}
|
||||
|
||||
# Bind the functions to key combinations
|
||||
bind -x '"\C-T": tv_smart_autocomplete'
|
||||
bind -x '"\C-R": tv_shell_history'
|
||||
|
||||
108
.bash/toolchains/vifm.sh
Normal file
108
.bash/toolchains/vifm.sh
Normal file
@@ -0,0 +1,108 @@
|
||||
#!/usr/bin/env bash
|
||||
# VIFM configuration - migrated from .bash_vifm
|
||||
|
||||
vifm() {
|
||||
\cat <<-"HELP"
|
||||
Use bash build-in:
|
||||
- cd (ch dir), ls or tree (list), find
|
||||
- mkdir (make dir), touch (make file), rm (remove)
|
||||
- cp (copy), mv (move+rename)
|
||||
- cat (print file), head (print first lines), tail (print last lines)
|
||||
- ln (link), chmod (change perm), chown (change owner)
|
||||
- file/dir info: stat , file , mimetype
|
||||
- cd stack: pushd, popd, dirs -v
|
||||
Use helpers:
|
||||
- rsync (copy), fd (verbo-less find), chafa (ascii images viewer)
|
||||
- m (marks, `cd "$m<name>"`), cd-kdialog
|
||||
- trash-* (trash)
|
||||
Use bash/terminal features:
|
||||
- history search (`cd …`)
|
||||
- tab completion
|
||||
- substitution: `!#:`, `!!:`
|
||||
- globbing: `*`, `?`, `{}` … `for file in *; do …; done`
|
||||
Use GUI:
|
||||
- open . or open <file/dir>
|
||||
- dolphin
|
||||
Use VIM:
|
||||
- ls > <batch>.sh → vim <batch>.sh → :wq → bash <batch>.sh
|
||||
Use vim aliases?:
|
||||
- y (yank), p (paste), P (paste and clear)
|
||||
- y [file(s)|dir(s)]; p | xargs -I{} <cp|mv|…> {} …; P
|
||||
Use `$PROMPT_COMMAND`:
|
||||
- `PROMPT_COMMAND+='; ls -A'; PROMPT_COMMAND="${PROMPT_COMMAND/; ls -A}"`
|
||||
HELP
|
||||
}
|
||||
|
||||
m() {
|
||||
if [[ "-d" == "$1" ]]; then
|
||||
unset "m$2"
|
||||
crossSession "m$2"
|
||||
return 0
|
||||
fi
|
||||
if [[ -z "$1" ]]; then
|
||||
printenv | grep -e '^m' | sort | xargs -I{} echo \${}
|
||||
return 0
|
||||
fi
|
||||
if [[ "--help" == "$1" ]]; then
|
||||
\cat <<-"HELP"
|
||||
m [--help]
|
||||
Lists all marks or print this help.
|
||||
m -d <name>
|
||||
Deletes mark <name>. Unsets variable and cross session variable.
|
||||
m <name> [path]
|
||||
Sets mark <name> to current directory or [path].
|
||||
The mark is just a bash variable, use `$m<name>`.
|
||||
cd $m<name>
|
||||
cd to mark <name>.
|
||||
HELP
|
||||
return 0
|
||||
fi
|
||||
local n="m$1"
|
||||
[[ -z "${!n}" ]] || return 1
|
||||
[[ -z "$2" ]] && local p="$(pwd)" || local p="$(readlink -f $2)"
|
||||
crossSession "$n" "$p"
|
||||
export $n="$p"
|
||||
}
|
||||
|
||||
alias cd-kdialog='cd "$(kdialog --getexistingdirectory --title "Vyberte složku" 2>/dev/null)"'
|
||||
alias fd='fdfind'
|
||||
|
||||
# vim-like aliases?
|
||||
alias dw='rm'
|
||||
alias cw='mv'
|
||||
alias g='fdfind'
|
||||
|
||||
# yanked files
|
||||
export YANKED=()
|
||||
p() {
|
||||
for f in "${YANKED[@]}"; do
|
||||
IFS=$'' echo "$f"
|
||||
done
|
||||
} # p | xargs -I{} …
|
||||
P() { YANKED=(); echo 'YANKED=()'; }
|
||||
y() {
|
||||
local pwd
|
||||
pwd="$(pwd)"
|
||||
if [[ -z "$1" ]]; then
|
||||
YANKED=("$pwd")
|
||||
else
|
||||
for f in "$@"; do
|
||||
if [[ "$f" == /* ]]; then
|
||||
YANKED+=("$f")
|
||||
elif [[ "$f" == ./* || "$f" == '.' ]]; then
|
||||
YANKED+=("$pwd${f:1}")
|
||||
else
|
||||
YANKED+=("$pwd/$f")
|
||||
fi
|
||||
done
|
||||
fi
|
||||
echo "$(p)"
|
||||
}
|
||||
|
||||
# tab completion
|
||||
[[ $(command -v _complete_alias) ]] || source "$BASH_DOTFILES/shell/complete-alias/complete_alias"
|
||||
source <(fdfind --gen-completions)
|
||||
complete -F _complete_alias fd
|
||||
complete -F _complete_alias dw
|
||||
complete -F _complete_alias cw
|
||||
complete -F _complete_alias g
|
||||
Reference in New Issue
Block a user