Fortunately, it a simple matter of programming to have a script take
each argument on the command line and pipe it through another grep.
Need to reduce result is as easy as hitting an up arrow to had another
value to the previous command.
As a matter of fact, you can make the script ambidextrous, for searching
man pages, locate, journalctl log, showrgb color selections,
systemctl list-units --type=service, spelling dictionary ....
Currently I have 50+ different searches.
For anyone wanting something to play with, here is your "ux" starter script.
-----8< ----8< ----8< ----8< cut below this line----8< ----8< ----8<
#! /bin/bash
#******************************************************************************
#*
#* ux - search different files with user supplied keywords. Version 2.3
#*
#* basename is called to determine command and file to use.
#*
#*
#* To add a new selection:
#* copy some_case_name stanza, set case_name, comment and
#* whatever commands needed.
#* create a link with ln -s ux new_case_name
#* or run the command ux -i
#*
#* Some linked example snippets: ls -l u*
#* ue -> ux
#* uh -> ux
#* uidx -> ux
#* ulocate -> ux
#* uman -> ux
#* urgb -> ux
#* urls -> ux
#* and to find a word in dictionary there is
#* sp -> ux
#*
#* sp usage example would be
#* sp amb d x to find ambidextrous
#*
#* Install procedure:
#* save this as ux
#* chmod +x ux
#* You install in any directory found in your $PATH variable. To check:
#* echo $PATH
#* Usual install location is /usr/local/bin, so
#* cp ux /usr/local/bin/ux
#* chmod +x /usr/local/bin/ux
#* cd /usr/local/bin
#* ux -i
#* cd
#*
#* Test:
#* ux
#* FYI: all commands may not work because I left some that depend
#* on files in my setup and to give you a stanza to work on.
#*
#* NOTE: Script requires xterm to be installed.
#* If you are going to use ujctl, your login needs to have the
#* systemd-journal group. If you add it, you need to log out/in
#* to pick up the new group.
#*
#*
#******************************************************************************
export PATH=\
/usr/local/sbin:/usr/sbin:sbin\
:/usr/local/bin:/usr/bin:/bin\
:/usr/libexec\
:/local/bin:$HOME/bin\
_cmd_line_args="$*"
which ux > /dev/null 2>&1
if [ $? -ne 0 ] ; then
which ux
echo "
ux needs to be in your path and you have followed the install procedure
"
exit 1
fi
_exe_fn=$(which ux)
_app=$(basename $0)
_node=$(hostname --short)
_tmp_fn=/$_app
_exe_dir=${_exe_fn%$_tmp_fn}
_xfont='-font 6x10 -geom 200'
_xcolor='-fg black -bg lightgrey'
_xlayout="-font 7x13 -geom 200 $_xcolor"
_tmp_fn=$HOME/tmp/$_app.x
_arg1=""
_args=""
_cmd_line=""
_tmp=""
#***************************
#* main code start here
#***************************
echo -ne '\033[?3h\033[?66h'
# echo "tput clear" >> $_tmp_fn
mkdir -p $HOME/tmp
/bin/cp /dev/null $_tmp_fn
echo "sleep 1" >> $_tmp_fn
case $_app in
ujctl)
_usage_args='bs:u:' # list of valid switches ':' indicates needs value
while getopts "$_usage_args" OPTION; do
case "$OPTION" in
b) _args="$_args -b" ;;
s) _args="$_args --since '$(date --date "$OPTARG" '+%Y-%m-%d %H:%M:%S')'" ;;
u) _args="$_args --until '$(date --date "$OPTARG" '+%Y-%m-%d %H:%M:%S')'" ;;
*)
echo "unrecognized $_app option $OPTION"
echo "$_cmd_line_args"
usage
;;
esac
done
if [ $OPTIND -gt 0 ] ; then
shift $((OPTIND-1))
set -- $*
fi
;;
ux)
set -- $_cmd_line_args
if [ $# -gt 0 ] ; then
if [ "$1" = "-i" ] ; then
cd $_exe_dir
while read -r line ; do
set -- $line
_fn=$1
if [ ! -e $_exe_dir/$_fn ] ; then
ln -sf $_exe_fn $_fn
fi
done < <(grep '#' $_exe_fn | grep ')' | tr -d '#)' | grep -v ux_fn )
echo "created:"
ls -al | grep -- '->'
exit 0
fi
fi
;;
*) ;;
esac
if [ $# -ne 0 ] ; then
_arg1=$1
shift
fi
while [ $# -ne 0 ] ; do
if [ $# -eq 1 ] ; then
_tmp=$_tmp" | grep --color -Eie \"$1\""
else
_tmp=$_tmp" | grep -Eie \"$1\""
fi
shift
done
case $_app in
sp) #- search spelling dictionary (assumes words,util-linux rpms installed)
echo "look \"$_arg1\" $_tmp" >> $_tmp_fn
;;
ualias) #- search ~/.bashrc /etc/bashrc
echo "echo -e \"\n# $_exe $_cmd_line\"" >> $_tmp_fn
echo "echo -e \"looking in $HOME/.bashrc\"" >> $_tmp_fn
echo "grep --color -Eie \"$_arg1\" $HOME/.bashrc $_tmp" >> $_tmp_fn
echo "echo -e \"looking in /etc/bashrc\"" >> $_tmp_fn
echo "grep --color -Eie \"$_arg1\" /etc/bashrc $_tmp" >> $_tmp_fn
;;
udir) #- search directory for file name
echo "ls -al | grep -Eie $_arg1 $_tmp" >> $_tmp_fn
;;
uenv) #- search for environment variable
echo "env |sort | grep -Eie \"$_arg1\" $_tmp" >> $_tmp_fn
;;
uh) #- search my /local/doc/unix.help file
echo "grep --color -Eie \"$_arg1\" /local/doc/unix.help $_tmp" >> $_tmp_fn
;;
ujctl) #- search journalctl log
echo "echo -e \"\n# looking in journalctl $_args \"" >> $_tmp_fn
echo "journalctl $_args | grep -Eie \"$_arg1\" $_tmp" >> $_tmp_fn
;;
ukernel) #- search /usr/share/doc/kernel-doc/
arr=(
"/usr/share/doc/kernel-doc/kernel-parameters.txt"
"/usr/share/doc/kernel-doc/video4linux/bttv/Insmod-options"
"/usr/share/doc/kernel-doc/networking/ip-sysctl.txt"
"/usr/share/doc/kernel-doc/vm/slub.txt"
"/usr/share/doc/kernel-doc/clk.txt"
"/usr/share/doc/kernel-doc/cgroups/memory.txt"
"/usr/share/doc/kernel-doc/x86/x86_64/boot-options.txt"
"/usr/share/doc/kernel-doc/block/cfq-iosched.txt"
"/usr/share/doc/kernel-doc/block/cmdline-partition.txt"
"/usr/share/doc/kernel-doc/blockdev/floppy.txt"
"/usr/share/doc/kernel-doc/blockdev/paride.txt"
"/usr/share/doc/kernel-doc/blockdev/ramdisk.txt"
"/usr/share/doc/kernel-doc/cgroups/cpusets.txt"
"/usr/share/doc/kernel-doc/debugging-via-ohci1394.txt"
"/usr/share/doc/kernel-doc/fb/modedb.txt"
"/usr/share/doc/kernel-doc/filesystems/nfs/nfsroot.txt"
"/usr/share/doc/kernel-doc/ide/ide.txt"
"/usr/share/doc/kernel-doc/input/joystick.txt"
"/usr/share/doc/kernel-doc/isdn/README.HiSax"
"/usr/share/doc/kernel-doc/kdump/kdump.txt"
"/usr/share/doc/kernel-doc/laptops/sonypi.txt"
"/usr/share/doc/kernel-doc/md.txt"
"/usr/share/doc/kernel-doc/networking/ipv6.txt"
"/usr/share/doc/kernel-doc/power/video.txt"
"/usr/share/doc/kernel-doc/s390/CommonIO"
"/usr/share/doc/kernel-doc/serial-console.txt"
"/usr/share/doc/kernel-doc/sound/alsa/alsa-parameters.txt"
"/usr/share/doc/kernel-doc/sound/oss/oss-parameters.txt"
"/usr/share/doc/kernel-doc/sysctl/vm.txt"
"/usr/share/doc/kernel-doc/video4linux/meye.txt"
"/usr/share/doc/kernel-doc/vm/transhuge.txt"
"/usr/share/doc/kernel-doc/watchdog/watchdog-parameters.txt"
"/usr/share/doc/kernel-doc/x86/boot.txt"
"/usr/share/doc/kernel-doc/x86/i386/IO-APIC.txt"
"/usr/share/doc/kernel-doc/x86/intel_mpx.txt"
"/usr/share/doc/kernel-doc/dynamic-debug-howto.txt"
)
for index in ${!arr[*]} ; do
echo "echo looking in ${arr[$index]} " >> $_tmp_fn
echo "grep --color -Eie \"$_arg1\" ${arr[$index]} $_tmp" >> $_tmp_fn
done
;;
ulocate) #- search system's locate database
echo "locate -i -- \"$_arg1\" $_tmp" >> $_tmp_fn
;;
uls) #- search ls results
echo "ls | grep -Eie $_arg1 $_tmp" >> $_tmp_fn
;;
uman) #- search apropos
echo "apropos \"$_arg1\" $_tmp" >> $_tmp_fn
;;
umanc) #- search apropos for C functions
echo "apropos \\(3\\) | grep -i \"$_arg1\" $_tmp | egrep -v \"::|DES_|Tcl_|XC|X|TCL_|^X\" " >> $_tmp_fn
;;
ups) #- search ps aux
echo "ps aux | grep -v $_app | grep -Eie \"$_arg1\" $_tmp" >> $_tmp_fn
;;
urgb) #- search showrgb color selections (assumes rgb rpm installed)
echo "showrgb | grep -Eie \"$_arg1\" $_tmp" >> $_tmp_fn
;;
urpm) #- search for installed rpm
echo "rpm -qa \"*$_arg1*\" $_tmp" >> $_tmp_fn
;;
userv) #- search /etc/services file
echo "grep --color -Eie \"$_arg1\" /etc/services $_tmp" >> $_tmp_fn
;;
uservers) #- search systemctl list-units --type=service
echo "systemctl list-units --all > $HOME/tmp/ctl.units" >> $_tmp_fn
echo "systemctl list-units --type=service >> $HOME/tmp/ctl.units" >> $_tmp_fn
echo "systemctl list-unit-files >> $HOME/tmp/ctl.units" >> $_tmp_fn
echo "sort -o $HOME/tmp/sys.tmp $HOME/tmp/ctl.units" >> $_tmp_fn
echo "rm --force $HOME/tmp/ctl.units" >> $_tmp_fn
echo "grep --color -Eie \"$_arg1\" $HOME/tmp/sys.tmp" >> $_tmp_fn
echo "rm --force $HOME/tmp/sys.tmp" >> $_tmp_fn
_xlayout=$_xfont
;;
usysctl) #- search /etc/sysctl.d/ /run/sysctl.d/ /usr/lib/sysctl.d/*.conf
echo "echo -e \"\n# $_exe $_cmd_line\"" >> $_tmp_fn
echo "echo -e \"looking in /etc/sysctl.d/*.conf\"" >> $_tmp_fn
echo "grep --color -Eie \"$_arg1\" /etc/sysctl.d/*.conf $_tmp" >> $_tmp_fn
echo "echo -e \"\nlooking in /run/sysctl.d/*.conf\"" >> $_tmp_fn
echo "grep --color -Eie \"$_arg1\" /run/sysctl.d/*.conf $_tmp" >> $_tmp_fn
echo "echo -e \"\nlooking in /usr/lib/sysctl.d/*.conf\"" >> $_tmp_fn
echo "grep --color -Eie \"$_arg1\" /usr/lib/sysctl.d/*.conf $_tmp" >> $_tmp_fn
;;
xmount) #- search mount igoring fs on, cgroup, systemd lines
if [ -z "$_arg1" ] ; then
echo "mount | sort -V | grep -v cgroup | grep -v systemd| grep -v devpts | grep -v sunrpc |
grep -v named | grep -v mqueue | grep -v /fs/ | grep -v \"fs on\" " >> $_tmp_fn
else
echo "mount | sort -V | grep -v cgroup | grep -v systemd| grep -v devpts | grep -v sunrpc |
grep -v named | grep -v mqueue | grep -v /fs/ | grep -v \"fs on\" | grep $_arg1 $_tmp" >> $_tmp_fn
fi
;;
*)
echo "grep --color -Eie '#' $_exe_fn | grep ')' | tr -d '#)' | grep -v ux_fn | sort" >> $_tmp_fn
echo "echo \" ==cmd== - ==== brief description ============================
For any of the above to work I assume you did a
cd $(dirname $_exe)
ln -s $_app each_above_cmd_here
or you need to run $_exe_fn -i
\"
" >> $_tmp_fn
;;
esac
echo "echo \" \"" >> $_tmp_fn
echo "echo \"# Completed: $_app $_cmd_line_args\"" >> $_tmp_fn
echo "read -p \"# hit return to close $_node $_tmp_fn\" var1 " >> $_tmp_fn
echo /bin/rm $_tmp_fn >> $_tmp_fn
chmod +x $_tmp_fn
nohup xterm -title "$_node $_exe $_cmd_line_args" $_xlayout -e $_tmp_fn \
> /dev/null 2>&1 &
#********************* end ux ******************************