9 Commits

Author SHA1 Message Date
6aed1cfbfd emacs: use vundo instead of undo-tree, .bashrc: cleanup. 2024-03-24 19:47:07 +01:00
cc5ae859a0 config lsp-ui-doc, etc... (see comments)
- configure lsp-ui-doc
- separate multiple cursor section
- Makefile-mode: Change fill-column to high, to prevent stupid indent
- Fix c-mode "/*" extra space on <return>
2024-03-02 09:45:55 +01:00
79955bb355 base.sh: add readline support for interective mode 2024-02-19 12:09:20 +01:00
b0f1f53865 Add negative decimal input, regex for prefixes, bits per int detection 2024-02-01 09:34:49 +01:00
f1fe945ecd add long options example 2024-01-31 13:25:03 +01:00
30a2954514 Fix bin() output and split(); add padding option. 2024-01-31 13:10:42 +01:00
d26c60e565 add ~/.local/bin in PATH 2024-01-26 07:54:34 +01:00
512c08ea31 remove less --auto-buffers option 2024-01-25 17:46:16 +01:00
4a14195bcd add bashrc.root 2024-01-23 09:52:04 +01:00
6 changed files with 515 additions and 172 deletions

View File

@@ -14,6 +14,31 @@
CMDNAME=${0##*/} # script name CMDNAME=${0##*/} # script name
# some default values (blocks separator padchar)
# Attention: For output base 10, obase is 1
declare -i ibase=0 obase=0 padding=0 prefix=1 ogroup=0 intbits
# find out int size (bits) - suppose 2-complement, and 8 bits char
printf -v _b "%x" -1
(( intbits = ${#_b} * 4 ))
declare -rA _bases=( # -f/-b accepted values
[2]=2 [b]=2 [B]=2
[8]=8 [o]=8 [O]=8
[10]=10 [d]=10 [D]=10
[16]=16 [h]=16 [H]=16
[a]=-1 [g]=-1
)
declare -A _pad=( # group separator
[2]=" " [8]=" " [10]="," [16]=" "
)
declare -rA _ogroup=( # group size
[2]=8 [8]=3 [10]=3 [16]=4
)
declare -rA _oprefix=( # output prefix
[2]="2#" [8]="0" [10]="" [16]="0x"
)
usage() { usage() {
printf "usage: %s [OPTIONS] [NUMBER]...\n" "$CMDNAME" printf "usage: %s [OPTIONS] [NUMBER]...\n" "$CMDNAME"
printf "Use '%s -h' for more help\n" "$CMDNAME" printf "Use '%s -h' for more help\n" "$CMDNAME"
@@ -22,13 +47,14 @@ usage() {
help() { help() {
cat << _EOF cat << _EOF
usage: $CMDNAME [OPTIONS] [NUMBER]... usage: $CMDNAME [OPTIONS] [NUMBER]...
-f, --from=BASE input base. Default is "g" -f, --from=BASE input base, see BASE below. Default is "g"
-t, --to=BASE output base. Default is "a" -t, --to=BASE output base, see BASE below. Default is "a"
-2, -8, -d, -x equivalent to -t2, -t8, -t10, -t16" -b, -o, -d, -x equivalent to -t2, -t8, -t10, -t16"
-g, --group=[SEP] group output (see OUTPUT below) -g, --group=[SEP] group output (see OUTPUT below)
-0, --padding Not implemented. 0-pad output on block boundary (implies -g) -p, --padding 0-pad output on block boundary (implies -g)
-n, --noprefix Remove base prefixes in output -n, --noprefix remove base prefixes in output
-h, --help this help -h, --help this help
-- end of options
$CMDNAME output the NUMBERS arguments in different bases. If no NUMBER is $CMDNAME output the NUMBERS arguments in different bases. If no NUMBER is
given, standard input will be used. given, standard input will be used.
@@ -40,67 +66,75 @@ BASE
16, h, H, 0x hexadecimal 16, h, H, 0x hexadecimal
a, g all/any: Default, guess format for '-f', output all a, g all/any: Default, guess format for '-f', output all
bases for '-t' bases for '-t'
INPUT NUMBER INPUT NUMBER
If input base is not specified, some prefixes are supported. If input base is not specified, some prefixes are supported.
'b' or '2/' for binary, '0', 'o' or '8/' for octal, '0x', 'x' or 'b' or '2/' for binary, '0', 'o' or '8/' for octal, '0x', 'x' or
'16/' for hexadecimal, and 'd' or '10/' for decimal. '16/' for hexadecimal, and 'd' or '10/' for decimal.
If no prefix, decimal is assumed. If no above prefix is found, decimal is assumed.
Decimal input may be signed or unsigned, with limits imposed by current
Bash (here: $intbits bits).
OUTPUT OUTPUT
By default, output is the input number converted in the 4 supported Decimal output is always unsigned.
bases (16, 10, 8, 2, in this order, separated by one tab character. By default, the input number is shown converted in the 4 supported
bases (16, 10, 8, 2, in this order), separated by one tab character.
Without '-n' option, all output numbers but decimal will be prefixed: Without '-n' option, all output numbers but decimal will be prefixed:
'2#' for binary, '0' for octal, '0x' for hexadecimal, making them '2#' for binary, '0' for octal, '0x' for hexadecimal, making them
usable for input in some otilities such as bash(1).] usable for input in some otilities such as bash(1).]
With '-g' option, number digits will be grouped by 3 (octal, With '-g' option, number digits will be grouped by 3 (octal,
decimal), or 4 (binary, hexadecimal)\n. If no SEP character is given, decimal), 4 (hexadecimal), or 8 (binary). If no SEP character is given,
the separator will be ',' (comma) for decimal, space otherwise. the separator will be ',' (comma) for decimal, space otherwise.
This option may be useless if default output, with multiple numbers This option may be useless for default output, with multiple numbers
on one line. on one line.
The '-0' option will left pad with '0' (zeros) to a group boundary. The '-p' option add 0 padding up to the base grouping boundary.
EXAMPLES EXAMPLES
Converting number in hexadecimal, decimal, octal, and binary, with or without
prefixes. Here, '\t' separator is shown as space:
$ $CMDNAME 0
0x0 0 0 2#0
$ $CMDNAME 123456 $ $CMDNAME 123456
2#11110001001000000 0361100 123456 0x1e240 0x1e240 123456 0361100 2#11110001001000000
$ $CMDNAME -n 123456
11110001001000000 361100 123456 1e240 $ $CMDNAME -n 2/100
$ $CMDNAME -ng2 012345 4 4 4 100
1 0100 1110 0101
$ $CMDNAME -n2 012345 $ $CMDNAME -n 0x1e240
1 0100 1110 0101 1e240 123456 361100 11110001001000000
Binary output, no prefix, grouped output:
$ $CMDNAME -bng 0x1e240
1 11100010 01000000
Negative input (decimal only):
$ $CMDNAME -x -- -1
0xffffffffffffffff
Input base indication, left padding binary output, no prefix:
$ $CMDNAME -nbp -f8 361100
00000001 11100010 01000000
Set group separator. Note that the separator *must* immediately follow the '-g'
option, without spaces:
$ $CMDNAME -nxg: 123456
1:e240
Long options, with separator and padding:
$ $CMDNAME --to=16 --noprefix --padding --group=: 12345
0001:e240
TODO
Add option for signed/unsigned integer output.
Remove useless octal output ?
_EOF _EOF
} }
# some default values (blocks separator padchar)
declare -i ibase=0 obase=0 padding=0 noprefix=0 ogroup=0
declare -rA _bases=(
[2]=2 [b]=2 [B]=2
[8]=8 [o]=8 [O]=8 [0]=8
[10]=10 [d]=10 [D]=10
[16]=16 [h]=16 [H]=16 [0x]=16
[a]=-1 [g]=-1
)
declare -A _pad=(
[2]=" " [8]=" " [10]="," [16]=" "
)
declare -rA _ogroup=(
[2]=4 [8]=3 [10]=3 [16]=4
)
declare -rA _oprefix=(
[2]="2#" [8]="0" [10]="" [16]="0x"
)
zero_pad() { zero_pad() {
local base="$1" str="$2" local n="$1" str="$2"
local str="$1"
local -i n=${_ogroup[$base]}
#printf "str=$str #=${#str}" >&2 printf "%0.*d%s" $(( n - ${#str} % n)) 0 "$str"
while (( ${#str} < $2 )); do
str="0$str"
done
printf "%s" "$str"
} }
split() { split() {
@@ -108,25 +142,32 @@ split() {
local res="$str" sep=${_pad[$base]} local res="$str" sep=${_pad[$base]}
local -i n=${_ogroup[$base]} local -i n=${_ogroup[$base]}
(( padding )) && str=$(zero_pad "${_ogroup[$base]}" "$str")
if (( ogroup )); then if (( ogroup )); then
res="" res=""
while (( ${#str} )); do while (( ${#str} )); do
if (( ${#str} < n )); then if (( ${#str} <= n )); then # finished
str=$(zero_pad "$str" $n) res="${str}${res:+$sep$res}"
break
fi fi
res="${str: -$n}${res:+$sep$res}" res="${str: -n}${res:+$sep$res}"
str="${str:0:-$n}" str="${str:0:-n}"
done done
fi fi
printf "%s" "$res" printf "%s" "$res"
} }
bin() { bin() {
local n bits="" local str=""
for (( n = $1 ; n > 0 ; n >>= 1 )); do local -i n dec="$1"
bits=$((n&1))$bits
# take care of negative numbers, as >> operator keeps the sign.
# 'intbits' is size of integer in bits in current shell.
for (( n = 0 ; dec && (n < intbits); n++ )); do
str="$(( dec & 1 ))$str"
(( dec >>= 1 ))
done done
printf "%s\n" "${bits-0}" printf "%s\n" "${str:-0}"
} }
hex() { hex() {
@@ -145,7 +186,7 @@ declare -a args=()
parse_opts() { parse_opts() {
# short and long options # short and long options
local sopts="f:t:28dxg::pnh" local sopts="f:t:bodxg::pnh"
local lopts="from:,to:,group::,padding,noprefix,help" local lopts="from:,to:,group::,padding,noprefix,help"
# set by options # set by options
local tmp="" local tmp=""
@@ -174,9 +215,9 @@ parse_opts() {
fi fi
shift shift
;; ;;
"-2") obase=2 ;; "-b") obase=2 ;;
"-8") obase=8 ;; "-o") obase=8 ;;
"-d") obase=10 ;; "-d") obase=1 ;;
"-x") obase=16 ;; "-x") obase=16 ;;
"-g"|"--group") "-g"|"--group")
ogroup=1 ogroup=1
@@ -185,47 +226,45 @@ parse_opts() {
fi fi
shift shift
;; ;;
"-p"|"--padding") padding=1 ;; "-p"|"--padding") ogroup=1; padding=1 ;;
"-n"|"--noprefix") noprefix=1 ;; "-n"|"--noprefix") prefix=0 ;;
"-h"|"--help") help ; exit 0 ;; "-h"|"--help") help ; exit 0 ;;
"--") shift; break ;; "--") shift; break ;;
*) usage; echo "Internal error [$1]!" >&2; exit 1 ;; *) usage; echo "Internal error [$1]!" >&2; exit 1 ;;
esac esac
shift shift
done done
# parse remaining arguments # next are numbers to convert, if any
if (($# > 0)); then # type if (($# > 0)); then
args=("$@") args=("$@")
fi fi
} }
# shellcheck disable=SC2317
addprefix() { addprefix() {
local base="$1" number="$2" local base="$1" number="$2" _prefix=""
local prefix="" if (( prefix )); then
(( noprefix )) || prefix="${_oprefix[$base]}" if [[ $base != 8 || $number != "0" ]]; then
printf "%s%s" "$prefix" "$number" _prefix="${_oprefix[$base]}"
fi
fi
printf "%s%s" "$_prefix" "$number"
} }
stripprefix() { stripprefix() {
local number="$1" [[ $1 =~ ^(0x|b|o|d|x|.*/) ]]
number=${number#0x} printf "%s" "${1#"${BASH_REMATCH[1]}"}"
number=${number#[bodx0]}
number=${number#0}
number=${number#*/}
printf "%s" "$number"
} }
guessbase() { guessbase() {
local input="$1" local input="$1"
local -i base=0 local -i base=0
if [[ $input =~ ^b || $input =~ ^2/ ]]; then if [[ $input =~ ^(b|2/) ]]; then
base=2 base=2
elif [[ $input =~ ^0x || $input =~ ^x || $input =~ ^16/ ]]; then elif [[ $input =~ ^(0x|x|16/) ]]; then
base=16 base=16
elif [[ $input =~ ^0 || $input =~ ^o || $input =~ ^8/ ]]; then elif [[ $input =~ ^(0|o|8/) ]]; then
base=8 base=8
elif [[ $input =~ ^d || $input =~ ^10/ ]]; then elif [[ $input =~ ^(d|10/) ]]; then
base=10 base=10
fi fi
return $(( base ? base : 10 )) return $(( base ? base : 10 ))
@@ -240,7 +279,9 @@ doit() {
fi fi
inum=$(stripprefix "$number") inum=$(stripprefix "$number")
(( decval = "$base#$inum" )) # input value in decimal # convert input value to decimal
(( base == 10 )) && (( decval = inum ))
(( base != 10 )) && (( decval = "$base#$inum" ))
# mask for desired output: 1=decimal, others are same as base # mask for desired output: 1=decimal, others are same as base
if (( ! _obase )); then if (( ! _obase )); then
@@ -270,7 +311,7 @@ doit() {
parse_opts "$@" parse_opts "$@"
if ! (( ${#args[@]} )); then if ! (( ${#args[@]} )); then
while read -ra line; do while read -era line; do
for input in "${line[@]}"; do for input in "${line[@]}"; do
doit "ibase" "$input" doit "ibase" "$input"
done done

View File

@@ -15,7 +15,7 @@
# i.e., add at the end of .bashrc: # i.e., add at the end of .bashrc:
# [ -f "$HOME/.bashrc.$USER" ] && . "$HOME/.bashrc.$USER" # [ -f "$HOME/.bashrc.$USER" ] && . "$HOME/.bashrc.$USER"
# #
# Debian default ~/.profile does: # Debian default ~/.profile usually does:
# 1) source .bashrc if it exists # 1) source .bashrc if it exists
# 2) add "$HOME"/bin in PATH # 2) add "$HOME"/bin in PATH
# This imply a duplicate "$HOME/bin" in PATH, as we do everything here. # This imply a duplicate "$HOME/bin" in PATH, as we do everything here.
@@ -78,10 +78,12 @@ _var_append() {
} }
# adjust PATH. Below paths will be added at beginning. # adjust PATH. Below paths will be added at beginning.
_lpath=("$HOME/bin/$(uname -s)-$(uname -m)" _lpath=("$HOME/bin/$(uname -s)-$(uname -m)" # architecture specific
"$HOME/bin" "$HOME/bin" # user scripts
"$HOME/.local/bin" # pip venv
#"$HOME/.cargo/bin" #"$HOME/.cargo/bin"
"/usr/local/bin") "/usr/local/bin"
)
# loop array in reverse order. Note: We do not test for path existence and add it # loop array in reverse order. Note: We do not test for path existence and add it
# unconditionally, to avoid automounter interference. # unconditionally, to avoid automounter interference.
@@ -100,7 +102,7 @@ ulimit -Sc 102400 # in 1024 bytes, 100Mb
if hash less 2>/dev/null; then if hash less 2>/dev/null; then
export PAGER=less export PAGER=less
# do not clear screen after "less", exit immediately if one page only # do not clear screen after "less", exit immediately if one page only
export LESS="-XFB" export LESS="--quit-if-one-screen --no-init"
# ... and just alias more... to less ;-) # ... and just alias more... to less ;-)
alias more=less alias more=less
fi fi
@@ -130,7 +132,8 @@ e() {
$VISUAL "$@" $VISUAL "$@"
} }
export -f e export -f e
if hash emacs 2>/dev/null; then
if hash emacs 2>/dev/null; then # look for Emacs...
# uncomment below to use full emacs # uncomment below to use full emacs
#export EDITOR=emacs #export EDITOR=emacs
# ... OR: uncomment below to use emacsclient # ... OR: uncomment below to use emacsclient
@@ -142,8 +145,7 @@ if hash emacs 2>/dev/null; then
alias emacs="emacsclient -c" alias emacs="emacsclient -c"
#alias crontab="VISUAL=emacsclient crontab -e" #alias crontab="VISUAL=emacsclient crontab -e"
#alias crontab="emacs-crontab.sh" #alias crontab="emacs-crontab.sh"
else else # ... or clones, vim/vi, etc...
# emacs clones, then vim/vi, then... whatever left.
_VISUALS=(zile jed mg e3em vim vi nano ed) _VISUALS=(zile jed mg e3em vim vi nano ed)
for e in "${_VISUALS[@]}"; do for e in "${_VISUALS[@]}"; do
@@ -156,8 +158,7 @@ else
fi fi
export EDITOR=$VISUAL export EDITOR=$VISUAL
# look for a pdf viewer for _pdfviewer in atril qpdfview; do # look for a pdf viewer
for _pdfviewer in qpdfview atril; do
if hash "$_pdfviewer" 2>/dev/null; then if hash "$_pdfviewer" 2>/dev/null; then
# shellcheck disable=SC2139 # shellcheck disable=SC2139
alias acroread="$_pdfviewer" alias acroread="$_pdfviewer"
@@ -189,7 +190,7 @@ export QUOTING_STYLE=literal
# avoid these stupid systemd defaults (horizontal scroll and pager) # avoid these stupid systemd defaults (horizontal scroll and pager)
alias systemctl="systemctl --no-pager --full" alias systemctl="systemctl --no-pager --full"
# useful aliases/functions # aliases/functions for usual commands (ls, history, grep...)
alias l='ls -F' alias l='ls -F'
alias ls='ls -F' alias ls='ls -F'
alias l1='ls -1F' alias l1='ls -1F'

View File

@@ -65,13 +65,14 @@ _vardir() {
# shellcheck disable=SC2139 # shellcheck disable=SC2139
alias "$_a"="$_x" alias "$_a"="$_x"
} }
_vardir AOC aoc + ~/dev/advent-of-code # Advent of code _vardir AOC aoc + ~/dev/advent-of-code # Advent of code
_vardir WCHESS wchess - ~/dev/www/crd/chess # raoult.com chess _vardir WCHESS wchess - ~/dev/www/crd/chess # raoult.com chess
_vardir CHESS chess + ~/dev/brchess # brchess _vardir CHESS chess + ~/dev/brchess # brchess
_vardir TOOLS tools - ~/dev/tools # tools _vardir CHESS brchess + ~/dev/brchess # brchess
_vardir BRLIB brlib - ~/dev/brlib # brlib _vardir TOOLS tools - ~/dev/tools # tools
_vardir EUD eud + ~/dev/eudyptula # eudyptula _vardir BRLIB brlib - ~/dev/brlib # brlib
_vardir DEV dev - ~/dev # dev _vardir EUD eud + ~/dev/eudyptula # eudyptula
_vardir DEV dev - ~/dev # dev
# Indent style for emacs # Indent style for emacs
# Local Variables: # Local Variables:

211
config/home/bashrc.root Normal file
View File

@@ -0,0 +1,211 @@
#!/usr/bin/env bash
#
# ~/.bashrc.root - root bash startup
#
# (C) Bruno Raoult ("br"), 2001-2024
# Licensed under the GNU General Public License v3.0 or later.
# Some rights reserved. See COPYING.
#
# You should have received a copy of the GNU General Public License along with this
# program. If not, see <https://www.gnu.org/licenses/gpl-3.0-standalone.html>.
#
# SPDX-License-Identifier: GPL-3.0-or-later <https://spdx.org/licenses/GPL-3.0-or-later.html>
#
# Usage: to be invoked from .bashrc.
# i.e., add at the end of .bashrc:
# [ -f "$HOME/.bashrc.$USER" ] && . "$HOME/.bashrc.$USER"
#
# Debian default ~/.profile usually does:
# 1) source .bashrc if it exists
# 2) add "$HOME"/bin in PATH
# This imply a duplicate "$HOME/bin" in PATH, as we do everything here.
# Better to have a ~/.bash_profile with the lines above.
# _var_del() - remove an element from a colon-separated list.
# $1: name (reference) of a colon separated list
# $2: element to remove (string)
#
# _var_del() removes every occurrence of $2, if there are more than 1,
# and leaves $1 unchanged if $2 is not present.
#
# Example:
# With VAR's value being "foo:bar:quax:bar". Using "_var_del VAR bar" will
# leave VAR with the value "foo:quax".
_var_del() {
local -n _p_del=$1
local _l=":$_p_del:"
while [[ $_l =~ :$2: ]]; do
_l=${_l//:$2:/:}
done
_l=${_l%:}
_l=${_l#:}
_p_del="$_l"
}
# _var_prepend() - prepend element to colon-separated variable.
# $1: variable name (reference)
# $2: element to add (string)
#
# Any occurrence of $2 in $1 is first removed, then $2 is added at $1 beginning.
#
# Example:
# With VAR's value being "foo:bar:quax:bar". Using "_var_prepend VAR bar"
# will leave VAR with the value "bar:foo:quax".
_var_prepend() {
local -n _p_prepend=$1
_var_del _p_prepend "$2"
[[ -z $_p_prepend ]] && _p_prepend="$2" && return
_p_prepend="$2:$_p_prepend"
}
# _var_append() - append element to colon-separated variable.
# $1: variable name (reference)
# $2: element to add (string)
#
# Any occurrence of $2 in $1 is first removed, then $2 is added at $1 end.
#
# Example:
# With VAR's value being "foo:bar:quax:bar". Using "_var_append VAR bar"
# will leave VAR with the value "foo:quax:bar".
_var_append() {
local -n _p_append=$1
_var_del _p_append "$2"
[[ -z $_p_append ]] && _p_append="$2" && return
_p_append="$_p_append:$2"
}
# adjust PATH. Below paths will be added at beginning.
_lpath=("$HOME/bin/$(uname -s)-$(uname -m)"
"$HOME/bin"
"/usr/local/bin")
# loop array in reverse order. Note: We do not test for path existence and add it
# unconditionally, to avoid automounter interference.
for (( _i = ${#_lpath[@]} - 1; _i >= 0; --_i )); do
_var_prepend PATH "${_lpath[_i]}"
done
unset _lpath
# enable core file
ulimit -HSc 102400 # in 1024 bytes - Really cannot use KiB :-)
# ... and set PAGER to less (for man(1) and others)
if hash less 2>/dev/null; then
export PAGER=less
# do not clear screen after "less", exit immediately if one page only
export LESS="-XFB"
# ... and just alias more... to less ;-)
alias more=less
fi
# no output split for dc and bc / make bc silent
export DC_LINE_LENGTH=0
export BC_LINE_LENGTH=0
export BC_ENV_ARGS=--quiet
# both ubuntu and debian assume we want colors if TERM contains "color"
# this is surely not true, as TERM is often forced by terminal emulator
# shellcheck disable=SC2154
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# trim prompt path
export PROMPT_DIRTRIM=3
# find a suitable editor
e() {
$VISUAL "$@"
}
export -f e
# no Emacs for root
# emacs clones, then vim/vi, then... whatever left.
_VISUALS=(zile mg jed vim vi nano ed)
for e in "${_VISUALS[@]}"; do
if hash "$e" 2>/dev/null; then
export VISUAL="$e"
break
fi
done
unset _VISUALS
export EDITOR=$VISUAL
# append to the history file, don't overwrite it
shopt -s histappend
# write history after each command
export PROMPT_COMMAND="history -a"
# Add timestamp in history
export HISTTIMEFORMAT="%d/%m %H:%M "
# ignore history dups, delete all previous dups
export HISTCONTROL="ignorespace:ignoredups:erasedups"
# ignore these in history
export HISTIGNORE="history *:h:hl:hll:hlll"
# history size
HISTSIZE=5000
HISTFILESIZE=5000
# remove new stupid Debian "ls" quoting, and colors...
# Many complains, one of them:
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=813164#226
export QUOTING_STYLE=literal
[[ -v BASH_ALIASES[ls] ]] && unalias ls
# aliases/functions for ls and history
alias l='ls -F'
alias ls='ls -F'
alias l1='ls -1F'
alias la='ls -AF'
alias ll='ls -lF'
alias lla='ls -lAF'
alias ldl='ls -l | grep ^d'
[[ -v BASH_ALIASES[lrt] ]] && unalias lrt
lrt() {
local -i _l=20
if (( $# > 0 )) && [[ $1 =~ [[:digit:]]+ ]]; then
_l="$1"
shift
fi
# shellcheck disable=2012
ls -lrt "${1:-.}" | tail -"$_l"
}
[[ -v BASH_ALIASES[lart] ]] && unalias lart
lart() {
local -i _l=20
if (( $# > 0 )) && [[ $1 =~ [[:digit:]]+ ]]; then
_l="$1"
shift
fi
# shellcheck disable=2012
ls -laFrt "${1:-.}" | tail -"$_l"
}
alias h="history 10" # short
alias hl="history 25" # long
alias hll="history 100" # very long
alias hlll="history" # all history
alias grep='grep --color=auto' # add colors to grep
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
# misc aliases
alias fuck='sudo $(history -p \!\!)'
alias diff='diff -u'
# Indent style for emacs
# Local Variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indentation: 4
# indent-tabs-mode: nil
# comment-column: 32
# End:

View File

@@ -15,6 +15,7 @@
;; (require 'use-package) ;; (require 'use-package)
(package-initialize) (package-initialize)
(setq use-package-always-ensure t) (setq use-package-always-ensure t)
(use-package delight :ensure t)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
;;(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/")) ;;(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/"))
@@ -75,6 +76,8 @@
(defun risky-local-variable-p (sym &optional _ignored) "Zoba SYM." nil) (defun risky-local-variable-p (sym &optional _ignored) "Zoba SYM." nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; swap modifier keysyms (japanese keyboard) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; swap modifier keysyms (japanese keyboard)
;; Done in .xmodmap
;;
;; windows key (super) becomes hyper ;; windows key (super) becomes hyper
;;(setq x-super-keysym 'hyper) ;;(setq x-super-keysym 'hyper)
;; alt key (meta) becomes super ;; alt key (meta) becomes super
@@ -253,23 +256,33 @@ Return new LIST-VAR value."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ggtags ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ggtags
(use-package ggtags (use-package ggtags
:ensure t :ensure t
:diminish ggtags-mode :diminish "gg"
:disabled t :disabled t
:defer t ;; :defer t
:after cc-mode
:init :init
(setq ggtags-global-window-height 28 (setq ggtags-global-window-height 28
ggtags-enable-navigation-keys nil) ggtags-enable-navigation-keys nil)
(add-hook 'c-mode-common-hook
(after cc-mode (add-hook 'c-mode-common-hook #'ggtags-mode)) (lambda ()
(when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
(ggtags-mode 1))))
;;(after cc-mode (add-hook 'c-mode-common-hook #'ggtags-mode))
:config :config
(bind-keys :map ggtags-mode-map (bind-keys :map ggtags-mode-map
("C-c g s" . ggtags-find-other-symbol) ;;("C-c g s" . ggtags-find-other-symbol)
("C-c g h" . ggtags-view-tag-history) ;;("C-c g h" . ggtags-view-tag-history)
("C-c g r" . ggtags-find-reference) ;;("C-c g r" . ggtags-find-reference)
("C-c g f" . ggtags-find-file) ;;("C-c g f" . ggtags-find-file)
("C-c g c" . ggtags-create-tags) ;;("C-c g c" . ggtags-create-tags)
("C-c g u" . ggtags-update-tags) ;;("C-c g u" . ggtags-update-tags)
("H-g s" . ggtags-find-other-symbol)
("H-g h" . ggtags-view-tag-history)
("H-g r" . ggtags-find-reference)
("H-g f" . ggtags-find-file)
("H-g c" . ggtags-create-tags)
("H-g u" . ggtags-update-tags)
("M-," 'pop-tag-mark))) ("M-," 'pop-tag-mark)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; projectile ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; projectile
@@ -277,6 +290,7 @@ Return new LIST-VAR value."
(use-package projectile (use-package projectile
;;:diminish projectile-mode ;;:diminish projectile-mode
:diminish " prj" :diminish " prj"
;; :delight
:ensure t :ensure t
:config :config
;;(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map) ;;(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
@@ -286,7 +300,9 @@ Return new LIST-VAR value."
;;projectile-indexing-method 'alien ;; does not use ".projectile" ;;projectile-indexing-method 'alien ;; does not use ".projectile"
projectile-indexing-method 'hybrid projectile-indexing-method 'hybrid
;;projectile-indexing-method 'native ;;projectile-indexing-method 'native
projectile-completion-system 'default) projectile-completion-system 'auto
projectile-tags-backend 'ggtags)
(add-to-list 'projectile-globally-ignored-files "*.png") (add-to-list 'projectile-globally-ignored-files "*.png")
(projectile-mode +1)) (projectile-mode +1))
@@ -300,8 +316,10 @@ Return new LIST-VAR value."
:config :config
(setq magit-delete-by-moving-to-trash nil (setq magit-delete-by-moving-to-trash nil
magit-clone-default-directory "~/dev/") magit-clone-default-directory "~/dev/")
(magit-auto-revert-mode -1)) (magit-auto-revert-mode -1)
:bind
(("C-c g" . magit-file-dispatch)
("C-x g" . magit-status)))
(use-package git-gutter (use-package git-gutter
:diminish :diminish
@@ -430,12 +448,14 @@ Return new LIST-VAR value."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Some useful setups ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Some useful setups
;; mouse ;; mouse
;; does not change point when getting focus - DOES NOT WORK ;; does not change point when getting focus - DOES NOT WORK
;;x-mouse-click-focus-ignore-position t ;; (setq x-mouse-click-focus-ignore-position t)
;;focus-follows-mouse nil ; must reflect WM settings ;;focus-follows-mouse nil ; must reflect WM settings
;;mouse-autoselect-window nil ; pointer does not select window ;;mouse-autoselect-window nil ; pointer does not select window
(global-set-key (kbd "C-h c") 'describe-char) (global-set-key (kbd "C-h c") 'describe-char)
(global-set-key (kbd "C-x 4 C-b") 'switch-to-buffer-other-window) (global-set-key (kbd "C-x 4 C-b") 'switch-to-buffer-other-window)
(global-unset-key [mode-line mouse-3]) ; so disturbing mouse-3 there !
;; next example maps C-x C-x to the same as C-c ;; next example maps C-x C-x to the same as C-c
;; (global-set-key (kbd "C-x C-x") (lookup-key global-map (kbd "C-c"))) ;; (global-set-key (kbd "C-x C-x") (lookup-key global-map (kbd "C-c")))
@@ -712,6 +732,25 @@ in whole buffer. With neither, delete comments on current line."
(while (re-search-forward "\\(^[[:space:]\n]+\\)\n" nil t) (while (re-search-forward "\\(^[[:space:]\n]+\\)\n" nil t)
(replace-match "\n")))) (replace-match "\n"))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; multiple cursors
(use-package multiple-cursors
:bind
(("C-c m t" . mc/mark-all-like-this)
("C-c m m" . mc/mark-all-like-this-dwim)
("C-c m l" . mc/edit-lines)
("C-c m e" . mc/edit-ends-of-lines)
("C-c m a" . mc/edit-beginnings-of-lines)
("C-c m n" . mc/mark-next-like-this)
("C-c m p" . mc/mark-previous-like-this)
("C-c m s" . mc/mark-sgml-tag-pair)
("C-c m d" . mc/mark-all-like-this-in-defun)
("C->" . mc/mark-next-like-this)
("C-<" . mc/mark-previous-like-this)
("C-S-<mouse-1>" . mc/add-cursor-on-click)
("C-M-m" . mc/mark-all-dwim)))
(use-package phi-search)
(use-package phi-search-mc :config (phi-search-mc/setup-keys))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; shell, eshell modes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; shell, eshell modes
;; will tell e-shell to run in visual mode ;; will tell e-shell to run in visual mode
'(eshell-visual-commands '(eshell-visual-commands
@@ -844,41 +883,34 @@ in whole buffer. With neither, delete comments on current line."
(global-set-key (kbd "C-x w") 'compare-windows) (global-set-key (kbd "C-x w") 'compare-windows)
;; multiple cursors ;; as dot-mode uses <insert>, we allow overwrite-mode with S-<insert>
(global-set-key (kbd "C->") 'mc/mark-next-like-this) (global-set-key (kbd "S-<insert>") 'overwrite-mode)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
(global-set-key (kbd "C-S-<mouse-1>") 'mc/add-cursor-on-click)
(global-set-key (kbd "C-M-m") 'mc/mark-all-dwim)
(global-set-key (kbd "C-x g") 'magit-status)
;; (global-set-key (kbd "s-SPC") 'delete-blank-lines)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; define my own keymap (s-c) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; define my own keymap (s-c)
;; first, define a keymap, with Super-c as prefix. ;; first, define a keymap, with Super-c as prefix.
(defvar my/keys-mode-map (make-sparse-keymap) ;; (defvar my/keys-mode-map (make-sparse-keymap)
"Keymap for my/keys-mode.") ;; "Keymap for my/keys-mode.")
(defvar my/keys-mode-prefix-map (lookup-key global-map (kbd "s-c")) ;; (defvar my/keys-mode-prefix-map (lookup-key global-map (kbd "s-c"))
"Keymap for custom key bindings starting with s-c prefix.") ;; "Keymap for custom key bindings starting with s-c prefix.")
;; (define-key my/keys-mode-map (kbd "s-c") my/keys-mode-prefix-map) ;; ;; (define-key my/keys-mode-map (kbd "s-c") my/keys-mode-prefix-map)
(define-minor-mode my/keys-mode ;; (define-minor-mode my/keys-mode
"A minor mode for custom key bindings." ;; "A minor mode for custom key bindings."
:lighter "s-c" ;; :lighter "s-c"
:keymap 'my/keys-mode-map ;; :keymap 'my/keys-mode-map
:global t) ;; :global t)
(defun my/prioritize-keys ;; (defun my/prioritize-keys
(file &optional noerror nomessage nosuffix must-suffix) ;; (file &optional noerror nomessage nosuffix must-suffix)
"Try to ensure that custom key bindings always have priority." ;; "Try to ensure that custom key bindings always have priority."
(unless (eq (caar minor-mode-map-alist) 'my/keys-mode) ;; (unless (eq (caar minor-mode-map-alist) 'my/keys-mode)
(let ((my/keys-mode-map (assq 'my/keys-mode minor-mode-map-alist))) ;; (let ((my/keys-mode-map (assq 'my/keys-mode minor-mode-map-alist)))
(assq-delete-all 'my/keys-mode minor-mode-map-alist) ;; (assq-delete-all 'my/keys-mode minor-mode-map-alist)
(add-to-list 'minor-mode-map-alist my/keys-mode-map)))) ;; (add-to-list 'minor-mode-map-alist my/keys-mode-map))))
(advice-add 'load :after #'my/prioritize-keys) ;; (advice-add 'load :after #'my/prioritize-keys)
;;(global-set-key (kbd "C-c t") #'make-temp-buffer) ;;(global-set-key (kbd "C-c t") #'make-temp-buffer)
;;(define-key my/keys-mode-prefix-map (kbd "r b") #'revert-buffer) ;;(define-key my/keys-mode-prefix-map (kbd "r b") #'revert-buffer)
@@ -998,27 +1030,59 @@ in whole buffer. With neither, delete comments on current line."
;;(define-key whole-line-or-region-local-mode-map [remap uncomment-region] nil) ;;(define-key whole-line-or-region-local-mode-map [remap uncomment-region] nil)
) )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; undo tree ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; vundo / undo-tree / winner
(use-package undo-tree ;; vundo config from :
:diminish undo-tree-mode ;; https://www.reddit.com/r/emacs/comments/txwwfi/vundo_is_great_visual_undotree_for_emacs28/
:defer t (use-package vundo
:init :commands (vundo)
(progn
(defalias 'redo 'undo-tree-redo)
(defalias 'undo 'undo-tree-undo)
(global-undo-tree-mode 1))
:config :config
(progn ;; Take less on-screen space.
(setq undo-tree-visualizer-timestamps t (setq vundo-compact-display t)
undo-tree-visualizer-diff t
undo-tree-enable-undo-in-region t ;; Better contrasting highlight.
;;undo-tree-auto-save-history t (custom-set-faces
) '(vundo-node ((t (:foreground "#808080"))))
(let ((undo-dir (concat my/emacs-tmpdir "/undo-tree/"))) '(vundo-stem ((t (:foreground "#808080"))))
(setq undo-tree-history-directory-alist '(vundo-highlight ((t (:foreground "#FFFF00")))))
`(("." . ,undo-dir)))
(unless (file-exists-p undo-dir) ;; Use `HJKL` VIM-like motion, also Home/End to jump around.
(make-directory undo-dir t))))) ;; (define-key vundo-mode-map (kbd "l") #'vundo-forward)
(define-key vundo-mode-map (kbd "<right>") #'vundo-forward)
;; (define-key vundo-mode-map (kbd "h") #'vundo-backward)
(define-key vundo-mode-map (kbd "<left>") #'vundo-backward)
;; (define-key vundo-mode-map (kbd "j") #'vundo-next)
(define-key vundo-mode-map (kbd "<down>") #'vundo-next)
;; (define-key vundo-mode-map (kbd "k") #'vundo-previous)
(define-key vundo-mode-map (kbd "<up>") #'vundo-previous)
(define-key vundo-mode-map (kbd "<home>") #'vundo-stem-root)
(define-key vundo-mode-map (kbd "<end>") #'vundo-stem-end)
(define-key vundo-mode-map (kbd "q") #'vundo-quit)
(define-key vundo-mode-map (kbd "C-g") #'vundo-quit)
(define-key vundo-mode-map (kbd "RET") #'vundo-confirm))
(global-set-key (kbd "C-x u") 'vundo)
;; (use-package undo-tree
;; :diminish undo-tree-mode
;; :defer t
;; :init
;; (progn
;; (defalias 'redo 'undo-tree-redo)
;; (defalias 'undo 'undo-tree-undo)
;; (global-undo-tree-mode 1))
;; :config
;; (progn
;; (setq undo-tree-visualizer-timestamps t
;; undo-tree-visualizer-diff t
;; undo-tree-enable-undo-in-region t
;; ;;undo-tree-auto-save-history t
;; )
;; (let ((undo-dir (concat my/emacs-tmpdir "/undo-tree/")))
;; (setq undo-tree-history-directory-alist
;; `(("." . ,undo-dir)))
;; (unless (file-exists-p undo-dir)
;; (make-directory undo-dir t)))))
;; useful to come back to working window after a buffer has popped up ;; useful to come back to working window after a buffer has popped up
;; C-c <left> to come back ;; C-c <left> to come back
@@ -1177,7 +1241,13 @@ in whole buffer. With neither, delete comments on current line."
;; (message "entering Makefile-mode") ;; (message "entering Makefile-mode")
(setq indent-tabs-mode t (setq indent-tabs-mode t
tab-width 8 tab-width 8
comment-column 60)) comment-column 60
comment-fill-column 120)
;;(defadvice comment-indent (around indent-to activate)
;; "Disable indent-tab-mode when indenting comment."
;; (lambda (fun &rest args) (let (indent-tabs-mode) (apply fun args))))
)
(add-hook 'makefile-mode-hook 'my/makefile-mode-hook) (add-hook 'makefile-mode-hook 'my/makefile-mode-hook)
@@ -1336,7 +1406,15 @@ in whole buffer. With neither, delete comments on current line."
comment-auto-fill-only-comments nil comment-auto-fill-only-comments nil
comment-style 'extra-line)) comment-style 'extra-line))
(add-hook 'c-mode-hook 'my/c-style) (use-package cc-mode
:ensure nil
:config
(add-hook 'c-mode-common-hook
(lambda ()
;;(when (derived-mode-p 'c-mode 'c++-mode 'java-mode 'asm-mode)
(when (derived-mode-p 'c-mode)
(ggtags-mode 1))))
(add-hook 'c-mode-hook 'my/c-style))
;;;;;;;;;;;;; linux kernel style ;;;;;;;;;;;;; linux kernel style
(defun c-lineup-arglist-tabs-only (ignored) (defun c-lineup-arglist-tabs-only (ignored)
@@ -2115,8 +2193,8 @@ The output will appear in the buffer *PHP*."
;;; c-mode ;;; c-mode
(sp-with-modes '(c-mode c++-mode) (sp-with-modes '(c-mode c++-mode)
(sp-local-pair "{" nil :post-handlers '(("||\n[i]" "RET"))) (sp-local-pair "{" nil :post-handlers '(("||\n[i]" "RET")))
(sp-local-pair "/*" "*/" :post-handlers '((" | " "SPC") (sp-local-pair "/*" "*/" :post-handlers '(("| " "SPC")
("* ||\n[i]" "RET")))) ("* ||\n[i]" "RET"))))
;;; markdown-mode ;;; markdown-mode
(sp-with-modes '(markdown-mode gfm-mode rst-mode) (sp-with-modes '(markdown-mode gfm-mode rst-mode)
(sp-local-pair "*" "*" :bind "C-*") (sp-local-pair "*" "*" :bind "C-*")
@@ -2174,7 +2252,7 @@ The output will appear in the buffer *PHP*."
;;lsp-enable-on-type-formatting nil ;;lsp-enable-on-type-formatting nil
lsp-enable-snippet nil lsp-enable-snippet nil
lsp-enable-symbol-highlighting t lsp-enable-symbol-highlighting t
lsp-lens-enable t lsp-lens-enable nil
lsp-headerline-breadcrumb-enable t lsp-headerline-breadcrumb-enable t
lsp-enable-indentation nil lsp-enable-indentation nil
lsp-enable-on-type-formatting nil lsp-enable-on-type-formatting nil
@@ -2183,6 +2261,8 @@ The output will appear in the buffer *PHP*."
lsp-modeline-code-actions-enable t lsp-modeline-code-actions-enable t
lsp-modeline-code-actions-segments '(count icon name) lsp-modeline-code-actions-segments '(count icon name)
lsp-signature-render-documentation t) lsp-signature-render-documentation t)
;;(define-key lsp-mode-map (kbd "<mouse-3>") nil)
;;(define-key lsp-mode-map (kbd "C-S-<mouse-3>") 'lsp-mouse-click)
:hook :hook
((sh-mode . lsp-deferred) ((sh-mode . lsp-deferred)
;;(c-mode-common . lsp-deferred) ;;(c-mode-common . lsp-deferred)
@@ -2192,14 +2272,22 @@ The output will appear in the buffer *PHP*."
:ensure t :ensure t
;;:diminish ;;:diminish
:config :config
(setq ; lsp-ui-doc-show-with-cursor t (setq lsp-ui-doc-show-with-cursor t
; lsp-ui-doc-show-with-mouse t lsp-ui-doc-show-with-mouse nil ; breaks isearch
lsp-ui-sideline-enable t
lsp-ui-sideline-show-code-actions t lsp-ui-sideline-enable nil ; too messy
lsp-ui-sideline-enable t
lsp-ui-sideline-show-hover t lsp-ui-sideline-show-hover t
lsp-ui-sideline-enable t lsp-ui-sideline-show-symbol t
lsp-ui-doc-enable nil) lsp-ui-sideline-show-code-actions t
;; lsp-ui-doc-enable nil
;; TRIED 2024/02/26
lsp-ui-doc-enable t
lsp-ui-doc-max-width 80
lsp-ui-doc-max-height 20
lsp-ui-doc-include-signature t ; type signature in doc
lsp-ui-doc-enhanced-markdown t ; looks b0rken (lists...)
lsp-ui-doc-position 'top ; top/bottom/at-point
lsp-ui-doc-alignment 'window)
:commands :commands
(lsp-ui-mode) (lsp-ui-mode)

View File

@@ -35,14 +35,15 @@
(defconst my/loaded-files-at-startup (defconst my/loaded-files-at-startup
(list (list
"~/dev/brlib/Makefile"
"~/dev/brchess/Makefile" "~/dev/brchess/Makefile"
"~/dev/brlib/Makefile"
;;"~/org/boot-disk.org" ;;"~/org/boot-disk.org"
;;"~/org/beaglebone-buster-setup.org" ;;"~/org/beaglebone-buster-setup.org"
;;"~/dev/www/cf.bodi/sql/coc.sql" ;;"~/dev/www/cf.bodi/sql/coc.sql"
;;"~/dev/www/cf.bodi/sql/coc-sql.org" ;;"~/dev/www/cf.bodi/sql/coc-sql.org"
user-init-file user-init-file
"~/dev/tools/bash/Makefile" ;; "~/dev/tools/bash/Makefile"
"~/dev/brchess/src/board.c"
"~/org/emacs-cheatsheet.org") "~/org/emacs-cheatsheet.org")
;;"~/dev/g910/g910-gkey-macro-support/lib/data_mappers/char_uinput_mapper.py" ;;"~/dev/g910/g910-gkey-macro-support/lib/data_mappers/char_uinput_mapper.py"
;;"~/dev/advent-of-code/2022/Makefile" ;;"~/dev/advent-of-code/2022/Makefile"