new laptop and clean up

- instead of vifm use bash and dolphin
This commit is contained in:
2025-09-19 14:47:38 +02:00
parent fe4109c0f1
commit 8f42578e4e
15 changed files with 206 additions and 615 deletions

View File

@@ -1,32 +1,24 @@
# Make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
alias gitdotfiles='/usr/bin/git --git-dir="$HOME/.dotfiles/" --work-tree="$HOME"'
# enable color support of ls and also add handy aliases
alias ls='ls -pQFh --group-directories-first'
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto -pQFh --group-directories-first'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias diff='diff --color=auto'
if [[ -r "$HOME/.dircolors" ]]; then
eval "$(dircolors -b "$HOME/.dircolors")"
else
eval "$(dircolors -b)"
fi
fi
alias ls='ls --color=auto -pQFh --group-directories-first'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias diff='diff --color=auto'
alias §rm='rm -vi'
alias §cp='cp -vi'
alias §mv='mv -vi'
alias §df='df -Th'
§du(){
[[ "$1" == '--help' ]] && echo "§du; §du '../*'" && return 0
du -h -x -s -- ${1:-*} | sort -r -h;
}
alias §xclip-copy='xclip -selection clipboard'
alias §xclip-paste='xclip -o -selection clipboard'
CROSS_SESSION="$BASH_DOTFILES/.bash_cross_session"
[ -f "$CROSS_SESSION" ] && . "$CROSS_SESSION"
crossSession() {
@@ -39,80 +31,43 @@ crossSession() {
echo ' Sets cross session variable <name> to <value> (or empty for unset).'
return 0
fi
if [[ '--list' == "$1" ]]; then
if [[ '--list' == "$1" ]]; then
cat "$CROSS_SESSION"
return 0
fi
local name="$1"
local value="$2"
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
# 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
}
cd(){
builtin cd "$@" || return $?
crossSession 'OLDPWD' "$(pwd)"
}
cd(){ builtin cd "$@" && crossSession 'OLDPWD' "$(pwd)"; }
history_clean(){ awk '!seen[$0]++ {print $0}' $HOME/.bash_history; }
history_edit(){ vim $HOME/.bash_history; }
history_cat(){ LC_ALL=C cat ~/.bash_history; }
history_most_used(){ LC_ALL=C cat ~/.bash_history | cut -d ';' -f 2- | §awk 1 | sort | uniq -c | sort -r -n | head -n ${1-10}; }
§(){
[[ -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 ~/bin | grep -P "^§" | sed 's/^§/~\/bin\/ §/'
\ls ~/.local/bin | grep -P "^§" | xargs -I{} echo '~/.local/bin/'{}
printenv | grep -e '^l' | xargs -I{} echo \${}
}
alias §less='less -R -S'
m(){
if [[ '-d' == "$1" ]]; then
unset "m$2"
crossSession "m$2"
return 0
fi
if [[ -z "$1" ]]; then
printenv | grep -e '^m'
return 0
fi
if [[ "--help" == "$1" ]]; then
echo 'm [--help]'
echo ' Lists all marks or print this help.'
echo 'm -d <name>'
echo ' Deletes mark <name>. Unsets variable and cross session variable.'
echo 'm <name> [path]'
echo ' Sets mark <name> to current directory or [path].'
echo ' The mark is just a bash variable, use `$m<name>`.'
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-vifm='cd `vifm --choose-dir -`'
mkcd(){ mkdir -p -- "$1" && cd -P -- "$1"; }
alias gcalendar-dovolené='gcalendar --account "práce" --calendar "Dovolené"'
alias gcalendar-události='gcalendar --account "default" --calendar "Události"'
alias §find.='find . -maxdepth 1'
alias pdftk='java -jar $HOME/bin/pdftk-all.jar'
bw-session(){
bw logout
@@ -126,12 +81,10 @@ bw-session(){
unset BW_CLIENTID
}
alias §psmem_all='ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem'
alias §psmem='§psmem_all | head -n 10'
alias §pscpu_all='ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu'
alias §pscpu='§pscpu_all | head -n 10'
alias §psnet_all='lsof -P -i -n'
alias §ck-grep='cat /usr/share/X11/locale/en_US.UTF-8/Compose ~/.XCompose | grep -i'
export lps_mem='-eo pid,ppid,cmd,%mem,%cpu --sort=-%mem'
export lps_cpu='-eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu'
export llsoft_all='-P -i -n'
export lgrep_compose='-i /usr/share/X11/locale/en_US.UTF-8/Compose ~/.XCompose'
§ping-test(){ # Pings ip address of noip.com and www.google.com.
ping -c 1 -q 8.23.224.107 | grep --color=never -A 1 -i '\---'
@@ -174,9 +127,17 @@ alias npx-markdown='npx -y markserv'
EOF
}
alias fzf=fzf-carroarmato0.fzf
alias smerge='/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=sublime_merge --file-forwarding com.sublimemerge.App @@u %u @@'
kommit(){ command kommit $* > /dev/null 2>&1 & disown; }
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
}
§url-curl(){ curl --silent -I "$1" | grep -i location; }

View File

@@ -1,18 +1,16 @@
eval "$(gh completion -s bash)"
# gh tips: https://gist.github.com/ChristopherA/3cca24936fb2c84786a29f67bacacd3e
# used ectension: heaths/gh-label
[[ $- != *i* ]] && return # dont include rest in Vim
[[ $- != *i* ]] && return # dont include rest in Vim
SCRIPT_DIR=$( builtin cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "$SCRIPT_DIR/complete-alias/complete_alias"
complete -F _complete_alias gitdotfiles
alias C--asana='eval "$($HOME/bin/asana.mjs completion_bash)"'
alias C--brew='\. "$BASH_DOTFILES/brew.completion"'
alias C--pnpm='\. "$BASH_DOTFILES/pnpm.completion"'
alias C--uu='eval "$($HOME/bin/uu --completion-bash)"'
alias C--uu='eval "$($HOME/.loacl/bin/uu --completion-bash)"'
alias C--jc='eval "$(jc -B)" … newer version needed'
alias C--gb='source <(gb completion bash) && complete -F __start_git-bug gb'
\. <(bs .completion bash)
\. "$BASH_DOTFILES/cordova.completion"
\. <(node --completion-bash)
@@ -20,32 +18,32 @@ alias C--gb='source <(gb completion bash) && complete -F __start_git-bug gb'
\. <(nodejsscript --completion bash)
_npx() {
local cur="${COMP_WORDS[COMP_CWORD]}"
local cur="${COMP_WORDS[COMP_CWORD]}"
if [[ $COMP_CWORD != 1 ]]; then
case "${COMP_WORDS[1]}" in
gulp)
local compls=$(npx gulp --tasks-simple)
if [[ $compls == *"__autocomplete_bash"* ]]; then
compls="$compls $(npx gulp -L __autocomplete_bash --_l=$COMP_CWORD --_c=$cur)"
fi
;;
esac
COMPREPLY=($(compgen -W "$compls" -- "$cur"))
return 0;
fi
if [[ $COMP_CWORD != 1 ]]; then
case "${COMP_WORDS[1]}" in
gulp)
local compls=$(npx gulp --tasks-simple)
if [[ $compls == *"__autocomplete_bash"* ]]; then
compls="$compls $(npx gulp -L __autocomplete_bash --_l=$COMP_CWORD --_c=$cur)"
fi
;;
esac
COMPREPLY=($(compgen -W "$compls" -- "$cur"))
return 0;
fi
local dir=$(pwd -P)
while [[ -n "$dir" ]]; do
if [[ ! -d $dir/node_modules/.bin ]]; then
dir=${dir%/*}
continue
fi
local execs=( `cd $dir/node_modules/.bin; find -L . -type f -executable` )
execs=( ${execs[@]/#.\//} )
COMPREPLY=( $(compgen -W "${execs[*]} serve" -- "$cur" ) )
break
done
local dir=$(pwd -P)
while [[ -n "$dir" ]]; do
if [[ ! -d $dir/node_modules/.bin ]]; then
dir=${dir%/*}
continue
fi
local execs=( `cd $dir/node_modules/.bin; find -L . -type f -executable` )
execs=( ${execs[@]/#.\//} )
COMPREPLY=( $(compgen -W "${execs[*]} serve" -- "$cur" ) )
break
done
}
complete -F _npx npx

93
.bash/.bash_vifm Normal file
View File

@@ -0,0 +1,93 @@
[[ $(command -v crossSession) ]] || source "$BASH_DOTFILES/.bash_aliases"
vifm() {
echo 'Use bash build-in:'
echo ' - cd (ch dir), ls or tree (list), find'
echo ' - mkdir (make dir), touch (make file), rm (remove)'
echo ' - cp (copy), mv (move+rename)'
echo ' - cat (print file), head (print first lines), tail (print last lines)'
echo ' - info (print file info), file (print file type), mimetype'
echo ' - ln (link), chmod (change perm), chown (change owner)'
echo ' - cd stack: pushd, popd, dirs -v'
echo 'Use helpers:'
echo ' - rsync (copy), fd (verbo-less find)'
echo ' - m (marks, `cd "$m<name>"`), cd-kdialog'
echo ' - trash-* (trash)'
echo 'Use bash/terminal features:'
echo ' - history search (`cd …`)'
echo ' - tab completion'
echo ' - substitution: `!#:`, `!!:`'
echo 'Use GUI:'
echo ' - open . or open <file/dir>'
echo ' - dolphin'
echo 'Use VIM:'
echo ' - ls > <batch>.sh → vim <batch>.sh → :wq → bash <batch>.sh'
}
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
echo 'm [--help]'
echo ' Lists all marks or print this help.'
echo 'm -d <name>'
echo ' Deletes mark <name>. Unsets variable and cross session variable.'
echo 'm <name> [path]'
echo ' Sets mark <name> to current directory or [path].'
echo ' The mark is just a bash variable, use `$m<name>`.'
echo 'cd $m<name>'
echo ' cd to mark <name>.'
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)"
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/complete-alias/complete_alias"
\. <(fdfind --gen-completions)
complete -F _complete_alias fd
complete -F _complete_alias dw
complete -F _complete_alias cw
complete -F _complete_alias g