if [ -x /usr/bin/nautilus ]; then FILE_MGR=/usr/bin/nautilus elif [ -x /usr/bin/dolphin ]; then FILE_MGR=/usr/bin/dolphin elif [ -x /usr/bin/krusader ]; then FILE_MGR=/usr/bin/krusader elif [ -x /usr/bin/konqueror ]; then FILE_MGR=/usr/bin/konqueror elif [ -x /usr/bin/pcmanfm ]; then FILE_MGR=/usr/bin/pcmanfm elif [ -x /usr/bin/thunar ]; then FILE_MGR=/usr/bin/thunar else FILE_MGR=/usr/bin/nautilus fi # safety features alias cp='cp -iv' alias mv='mv -iv' alias ln="ln -i" # prompt whether to remove destinations alias chown="chown --preserve-root" alias chmod="chmod --preserve-root" alias chgrp="chgrp --preserve-root" alias rm='rm -I --preserve-root' if [ -x /usr/bin/lsd ]; then alias ls='lsd' alias l='lsd -a' else alias l='ls -CF' fi # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" if [ -x /usr/bin/lsd ]; then alias ls='lsd --color=auto' else alias ls='ls --color=auto' fi alias dir='dir --color=auto' alias vdir='vdir --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi # some more ls aliases ll() { if [ -x /usr/bin/lsd ]; then if [ $(lsd -alF --color=always $@ | wc -l) -gt 20 ]; then lsd -alF --color=always $@ | less -R -X else lsd -alF --color=always $@ fi else if [ $(ls -alF --color=always $@ | wc -l) -gt 20 ]; then ls -alF --color=always $@ | less -r -X else ls -alF --color=always $@ fi fi } alias la='ls -alh' alias ls-la='ls -la' new-stuff-only-sub-dirs-too() { if [ -x /usr/bin/lsd ]; then find . -type d -name '.git' -prune -o -type f -newermt "$(date -d '14 days ago' +%Y-%m-%d)" -exec /usr/bin/lsd -lt --color=always {} + else find . -type d -name '.git' -prune -o -type f -newermt "$(date -d '14 days ago' +%Y-%m-%d)" -exec /usr/bin/ls -lt {} + fi } new-stuff-only() { if [ -x /usr/bin/lsd ]; then find . -maxdepth 1 -type f -newermt "$(date -d '14 days ago' +%Y-%m-%d)" -exec /usr/bin/lsd -lt --color=always {} + else find . -maxdepth 1 -type f -newermt "$(date -d '14 days ago' +%Y-%m-%d)" -exec /usr/bin/ls -lt {} + fi } alias dirs="ls -al | grep '^d'" alias cls='clear' #Sort by file size alias lt='/bin/ls --human-readable --size -1 -S --classify' alias sym-links='find -type l' show() { if [ -z $1 ]; then $FILE_MGR . & else $FILE_MGR $1 & fi } cdocs() { $FILE_MGR ~/Documents/"$1" & } documents() { cd ~/Documents/"$1" } downloads() { cd ~/Downloads/"$1" } desktop() { cd ~/Desktop/"$1" } music() { cd ~/Music/"$1" } videos() { cd ~/Videos/"$1" } photos() { cd ~/Pictures/"$1" } alias aliases='cd $_ENV_PATH' alias space-used='ncdu' www() { cd /var/www/"$1" } alias md='mkdir -p' mcd() { mkdir -p "$1" cd "$1" } alias e='exit' alias bye='exit' # Auto cd into folder by just typing the name of the directory shopt -s autocd #Search for a specific file #Use: "findfile example" #Results: prints any files that begin with "example", is not case-sensitive, picks up any file type (ex. result: ExampleTest.docx) findfile() { if [ -x /usr/bin/fdfind ]; then fdfind "$@" return fi file="$@" file+="*" find . -iname "$file" 2>&1 | grep -v "Operation not permitted" } #Search for all files with a specific extension #Use: "findext swift" #Results: prints all .swift files findext() { ext="*." ext+="$@" find . -iname "$ext" 2>&1 | grep -v "Operation not permitted" } lfile() { findfile "$@" | less } lext() { findext "$@" | less } # same as cp file{,_BACKUP} cpt() { if [ -z "$1" ]; then echo "cpt file file_BACKUP" echo "Will copy the file to file_BACKUP" echo "Same as doing: cp file{,_BACKUP}" return fi if [ -z "$2" ]; then cp "$1" "$1"_BACKUP else cp "$1" "$1"_"$2" fi } # same as mv dirname{,_OLD} mvt() { if [ -z "$1" ]; then echo "mvt existingDir newName" echo "Will rename the folder with existingDir_newName" echo "Same as doing: mv DirName{,_OLD}" return fi if [ -z "$2" ]; then mv "$1" "$1"_OLD else mv "$1" "$1"_"$2" fi } # mv file to ORIGNAL_file, make/edit new file erase_config() { if [ -z "$1" ]; then echo "Rename, then Erase Config File, then edit new one." return fi mv "$1" ORIGNAL_"$1" touch "$1" $EDITOR "$1" } # Find text within given files lookfor() { if [ -x /usr/bin/rg ]; then rg "$@" return fi if [ -z "$2" ]; then grep -rnw . -e "$1" else if [ -z "$3" ]; then grep -rnw "$2" -e "$1" else grep "$3" -rnw "$2" -e "$1" fi fi } # list all files of type and do line count Example: list-count *.yaml list-count() { total_files=$(ls -1 "$@" | wc -l) echo "Total # of files = $total_files" } tree-count() { tree -P "$@" -I "tmp|node_modules|vendor|cache|test" } alias file-count='find . -type f | wc -l' alias see-mounted="mount | awk -F' ' '{ printf \"%s\t%s\n\",\$1,\$3; }' | column -t | egrep ^/dev/ | sort"