source bash_func - Programming On Unix

Users browsing this thread:
budRich
Long time nixers
Less is more, here are some very simple functions that I always source in to my .bashrc

Code:
# prints newest file in dir
function lat() { ls -t | head -1 ;}

# example:
$ cd Downloads/EducationalVideos
$ mpv `lat`

Code:
# adds an alias and re-sources .bashrc
# not perfect improvements are very welcome
adda(){
  al=$1
  shift 1
  echo "alias $al='${@}'" >> $HOME/.bash/alias
  . $HOME/.bashrc
}

# example:
$ adda lolello echo hello | toilet | lolcat

# adds: alias lolello='echo hello | toilet | lolcat' - to ~/.bash/alias

I also use some of the nuggets from this thread on another forum:
https://linuxbbq.org/bbs/viewtopic.php?f=4&t=2076
venam
Administrators
One of my fav:
Code:
markdown () {
    markdown_py $1 | lynx -stdin
}
Or when you mess up your tty
Code:
alias vtn='echo "X[mX(BX)0OX[?5lX7X[rX8" | tr "XO" "\033\017"'
# or
alias vtm='stty;tput reset'

And the classic extract:
Code:
extract () {
    if [ -f $1 ] ; then
    case $1 in
        *.tar.bz2)   tar xvjf $1    ;;
        *.tar.gz)    tar xvzf $1    ;;
        *.bz2)       bunzip2 $1     ;;
        *.rar)       unrar e $1       ;;
        *.gz)        gunzip $1      ;;
        *.tar)       tar xvf $1     ;;
        *.tbz2)      tar xvjf $1    ;;
        *.tgz)       tar xvzf $1    ;;
        *.zip)       unzip $1       ;;
        *.Z)         uncompress $1  ;;
        *.7z)        7z x $1        ;;
        *)           echo "don't know how to extract '$1'..." ;;
    esac
    else
        echo "'$1' is not a valid file!"
    fi
}
pkal
Long time nixers
Here's a nifty music playing function from the arch wiki (one doesn't have to use "worstaudio", but I usually do just for the sake of speed - my speakers are bad enough anyway):
Code:
function mm() {
    mpv --no-video --ytdl-format=worstaudio "ytdl://ytsearch:$@"
}

And colourized man pages, from some default debian bashrc:
Code:
man() {
        env \
                LESS_TERMCAP_mb=$(printf "\e[1;31m") \
                LESS_TERMCAP_md=$(printf "\e[1;31m") \
                LESS_TERMCAP_me=$(printf "\e[0m") \
                LESS_TERMCAP_se=$(printf "\e[0m") \
                LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
                LESS_TERMCAP_ue=$(printf "\e[0m") \
                LESS_TERMCAP_us=$(printf "\e[1;32m") \
                EDITOR="" \
                man "$@"
}

(16-11-2017, 08:04 AM)venam Wrote: Or when you mess up your tty
Code:
alias vtn='echo "X[mX(BX)0OX[?5lX7X[rX8" | tr "XO" "\033\017"'
# or
alias vtm='stty;tput reset'

What's the difference between this and just regular "reset"?
venam
Administrators
(16-11-2017, 07:15 PM)zge Wrote: What's the difference between this and just regular "reset"?
Code:
stty sane   # reset line discipline
tput reset  # reset escape sequences (same as reset)