Created
September 16, 2022 06:24
-
-
Save Piqlet/37292470e703cf4c251c34e8aa571ded to your computer and use it in GitHub Desktop.
Simple terminal help for easier use of commands. 16/09/2022
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.bashrc : | |
# folder,export PATH : Private path where the "type -p" command will find your own files. | |
# source : Short .bashrc entry to make the original .bashrc more transparent. Custom settings and files in a separate directory. Easily portable, i.e. modular architecture. | |
folder=~/Downloads/bash && export PATH="$folder:$PATH" && source bash_settings | |
~/Downloads/bash/bash_settings : | |
(or "$folder"/bash_settings :) | |
# function m like menu | |
# | |
# fake readline (up and delete line) source : | |
# https://stackoverflow.com/questions/18362837/how-to-display-and-refresh-multiple-lines-in-bash | |
# https://stackoverflow.com/questions/22322879/how-to-print-current-bash-prompt | |
# | |
# fzf insert = edit source : | |
# https://github.com/junegunn/fzf/wiki/examples#opening-files | |
# | |
# neccesary packages : | |
# coreutils : head, tail | |
# ncurses : tput | |
function m { | |
line=$(< $(type -p $1.txt) fzf --reverse --exact --no-color --no-info --expect=insert) | |
# fzf escape or ctrl-c | |
if [ "$line" = "" ] | |
then | |
# fake readline (up and delete line) | |
tput cuu1 && tput el | |
return | |
fi | |
key=$(head -1 <<< "$line") | |
cmd=$(head -2 <<< "$line" | tail -1) | |
# fzf insert = edit | |
if [ "$key" = insert ] | |
then | |
# fake readline (up and delete line) | |
tput cuu1 && tput el | |
read -p "${PS1@P}" -eri "$cmd" cmd | |
fi | |
history -s "m "$1 | |
history -s $cmd | |
# fake readline (up and delete line) | |
tput cuu1 && tput el | |
echo "${PS1@P}"$cmd | |
eval $cmd | |
} | |
# example : alias h='m help' : "$folder"/help.txt : list of commands | |
alias h='m help' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment