From 6e1d27a7138b196aaee83742352287bbf720f442 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Tue, 28 Jan 2025 16:04:15 +0100 Subject: bash: handle missign commands --- .bashrc | 96 +++++++++++++--------------------------------------------------- .profile | 16 ++++++----- bin/os | 15 ++++++++++ 3 files changed, 43 insertions(+), 84 deletions(-) create mode 100755 bin/os diff --git a/.bashrc b/.bashrc index 55d4eb0..80bb8a2 100644 --- a/.bashrc +++ b/.bashrc @@ -18,70 +18,43 @@ stty -ixon # disable Ctrl-S # Save and reload the history after each command finishes #export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" -case $(uname -o) in -(Android) - PATH=~/bin:${HOME%/*}/usr/bin:~/go/bin +case $OS in +(arch|alpine) export GNUTERM='sixelgd enhanced truecolor font "arial,9"' - alias ls='eza' - alias ll='eza -lao --no-user --no-permissions' + alias ls='ls --color=auto -v' + alias ll='ls -AlFhv' + [ -f /etc/arch-release ] || trap 'printf "\e]2;${PWD/~/\~} ${BASH_COMMAND%ps1}\a"' DEBUG ;; (Darwin) export GNUTERM='sixelgd enhanced truecolor size 1600,1200 font "arial,9"' alias ls='ls -GF' alias ll='ls -AlGFhv' alias ldd='otool -L' + alias ibrew='arch -x86_64 /usr/local/bin/brew' trap 'printf "\e]2;${PWD/~/\~} ${BASH_COMMAND%update_terminal_cwd}\a"' DEBUG ;; -(GNU/Linux|Linux) +(termux) + PATH=~/bin:${HOME%/*}/usr/bin:~/go/bin export GNUTERM='sixelgd enhanced truecolor font "arial,9"' - alias ls='ls --color=auto -v' - alias ll='ls -AlFhv' - [ -f /etc/arch-release ] || trap 'printf "\e]2;${PWD/~/\~} ${BASH_COMMAND%ps1}\a"' DEBUG + alias ls='eza' + alias ll='eza -lao --no-user --no-permissions' ;; esac -# Change font for urxvt. Examples: -# cf 9x15 -# cf xft:Monospace:size=12 -# cf "xft:Bitstream Vera Sans Mono:size=8:antialias=true -# cf() { printf '\e]710;%s\007' "${1:-fixed}"; } - p() { [ -f "$1" -a ! -x "$1" ] && less "$1" || "$@" 2>&1 | less; } export -f p -fixab() { printf "\x1f\x8b\x08\x00\x00\x00\x00\x00"; tail -c +25 "$1"; } - -# Less: use colors in place of bold/underline -# red: 1, green: 2, yellow: 3, blue: 4, magenta: 5, cyan: 6, grey: 7, black: 8 -#export LESS_TERMCAP_md=$(tput setaf 4) # bold (blue) -#export LESS_TERMCAP_me=$'\E[0m' # end bold -#export LESS_TERMCAP_us=$(tput setaf 5) # underline (magenta) -#export LESS_TERMCAP_ue=$'\E[0m' # end underline export LESS=iXFRx4 #export BACKUP=bip:/home/backup/marc@$(hostname -s) -export LESS=XFRx4 # Stopwatch alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date' -#export TERMINAL=xt - -#alias cl='cf xft:Mono:size=12' -#alias cp='cp --reflink' alias grep='grep -i --color' alias more='less' alias vi='vim' alias view='vim -R' -#alias ldd='otool -L' # Darwin only -alias ibrew='arch -x86_64 /usr/local/bin/brew' -#alias op='xdg-open' -#alias git='hub' -#alias go='go1.14.1' -#alias go11='go1.11.13' -#alias go12='go1.12.10' -#alias go13='go1.13.8' -#alias go14='go1.14.2' alias gob='go build' alias goh='p go help' alias god='p go doc' @@ -89,16 +62,11 @@ alias gol='GO111MODULE=off go' alias gtr='go test -v -run' alias gtb='go test -v -cpuprofile cpu.out -memprofile mem.out -benchmem -bench' alias ww='vi ~/Wiki/home_page.md' -alias s='vi ~/Wiki/scratch.md' alias dotfiles='git --git-dir=$HOME/dotfiles --work-tree=$HOME' alias apk='doas apk' -#alias by='go build ./cmd/yaegi' -#alias cy='cd ~/go/src/github.com/traefik/yaegi' -#alias ty='go test -v -short ./interp' alias y='rlwrap -pblue yaegi' alias dy='YAEGI_AST_DOT=1 YAEGI_CFG_DOT=1 ./yaegi' -#alias wai='~/go/src/github.co/traefik/whoami/whoami' # yaegi debug export YAEGI_DOT_CMD='dotty -' @@ -106,29 +74,8 @@ export YAEGI_UNSAFE=1 export YAEGI_UNRESTRICTED=1 export YAEGI_SYSCALL=1 -#mosht() { mosh "$@" -- tmux new -A; } -#export -f mosht - -#ssht() { ssh -t "$@" -- tmux new -A; } -#export -f ssht - sshs() { ssh -t "$@" -- screen -d -R; } -#mpvx() { mpv --vo=sixel --profile=sw-fast --really-quiet "$@"; } -#export -f mpvx - -#tfk() { ~/go/src/github.com/traefik/traefik/traefik "$@"; } -#export -f tfk - -#ty() { go test -v -short ./interp; } -#export -f ty - -#ws() (cd ~/Wiki && git status --short) -#export -f ws - -#wsd() (cd ~/Wiki && git add . && git diff --cached) -#export -f wsd - man() { local width='' [ $(tput cols) -gt 88 ] && width='MANWIDTH=88' @@ -141,22 +88,17 @@ meteo() { curl -H "Accept-Language: fr" --compressed "$request" } -#PS1='[\u@\h \W]\$ ' - eval "$(fzf --bash)" >/dev/null -# Arch: display package to install for missing commands -#[ -f '/usr/share/doc/pkgfile/command-not-found.bash' ] && . /usr/share/doc/pkgfile/command-not-found.bash +# Handle missing commands, unless already provided. +type -t command_not_found_handle >/dev/null || command_not_found_handle() { + case $OS in + (alpine) pkgs=$(apk list -Pq "cmd:$1" | awk '{print $2}') ;; + (arch) pkgs=$(pkgfile -b "$1") ;; + (Darwin) pkgs=$(brew which-formula "$1") ;; + esac + echo "$1: command not found${pkgs:+. Present in: $pkgs}" >&2 +} # Display git status in prompt . ~/.bash-powerline.sh - -# load Nix config files (aka auto-completion etc.) -#export XDG_DATA_DIRS="$HOME/.nix-profile/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" -# eval "$(direnv hook bash)" -#export GITHUB_TOKEN=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 - -#set -o vi -#bind -m vi-command ".":insert-last-argument -#bind -m vi-command 'Control-l: clear-screen' -#bind -m vi-insert 'Control-l: clear-screen' diff --git a/.profile b/.profile index 52b0258..cdc28e3 100644 --- a/.profile +++ b/.profile @@ -1,8 +1,11 @@ # ~/.profile -case $(uname -o) in -(Android) - PATH=~/bin:${HOME%/*}/usr/bin:~/go/bin +export OS=$(~/bin/os) + +case $OS in +(arch|alpine) + PATH=~/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:~/go/bin + export XDG_RUNTIME_DIR=/run/user/$(id -u) ;; (Darwin) PATH=~/bin:~/mu/bin:/opt/homebrew/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/opt/tcl-tk/bin:$PATH:~/go/bin:~/.cargo/bin:~/.pyenv/versions/2.7.18/bin:~/.local/bin @@ -12,13 +15,12 @@ case $(uname -o) in eval "$(ssh-agent -s)" ssh-add fi - . "/opt/homebrew/etc/profile.d/bash_completion.sh" + . /opt/homebrew/etc/profile.d/bash_completion.sh tabs -4 export HOMEBREW_NO_ANALYTICS=1 ;; -(Linux|GNU/Linux) - PATH=~/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:~/go/bin - export XDG_RUNTIME_DIR=/run/user/$(id -u) +(termux) + PATH=~/bin:${HOME%/*}/usr/bin:~/go/bin ;; esac diff --git a/bin/os b/bin/os new file mode 100755 index 0000000..d9c7002 --- /dev/null +++ b/bin/os @@ -0,0 +1,15 @@ +#!/bin/sh + +# Print operating system name + +s=$(uname) +case $s in +(Linux) + if [ -f /etc/os-release ]; then + . /etc/os-release && [ "$ID" ] && s="$ID" + elif [ -d /data/data/com.termux ]; then + s=termux + fi + ;; +esac +echo "$s" -- cgit v1.2.3