Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # /home/user/.bashrc
- PATH="${HOME}/.local/bin:${HOME}/bin:${HOME}/Downloads/bin:${PATH}"
- # Some variables that change how ~/.bash_history works.
- PROMPT_COMMAND='history -a'
- HISTCONTROL="ignoredups:erasedups"
- HISTSIZE=10000
- LD_LOADER_PATH="/usr/local/lib:${LD_LOADER_PATH}"
- # Creates a backup of the $IFS variable.
- IFS_bak="$IFS"
- # Creates a pause message, for read / sudo prompts.
- pause_msg='Press Enter to continue...'
- # Declaring some aliases...
- alias dnf_files='dnf repoquery -l'
- alias dnf_groups_all='dnf group list --available'
- alias dnf_groups='dnf group list --installed'
- alias dnf_list='rpm -qa | sort'
- alias which_pkg='rpm -qf'
- alias cue_verify='whipper image verify'
- alias burn_img='cdrdao write --device /dev/sr0 --speed 2'
- alias read_img='cdrdao read-cd --device /dev/sr0 --read-raw --datafile'
- alias shellcheck='shellcheck -s bash'
- alias mate_restart='killall -15 mate-panel'
- alias kill_wine='wineserver --kill'
- alias temp='watch -n 2 sensors'
- alias temp_config='sudo sensors-detect'
- alias cpu_clock='watch -n.1 "grep \"^[c]pu MHz\" /proc/cpuinfo"'
- alias ps_handbrake='ps -C HandBrakeCLI -o pid,tty,stat,etime,cmd'
- alias freenet="${HOME}/freenet/run.sh"
- alias ipredator="${HOME}/bin/ipredator.sh"
- alias io_stats='sudo iotop -a -o -P'
- alias frag_level_xfs='xfs_db -c frag -r'
- alias chrome_ram='browser_ram.sh chrome normal'
- alias chrome_kill='browser_kill.sh chrome'
- alias pulse_reset='pactl set-sink-volume 0 100%'
- alias pipewire_reset='systemctl --user restart pipewire pipewire-pulse'
- alias is_game2ram_running='ps -C game2ram.sh'
- alias irc_logs="cd ${HOME}/.local/share/konversation/logs"
- alias import_flac="sudo ${HOME}/bin/import.pl ${HOME}/Music/FLAC"
- alias fix_flac_tags="sudo ${HOME}/bin/replaygain.pl ${HOME}/Music/FLAC"
- alias check_smart='sudo smartctl -a'
- alias drop_cache='sudo bash -c "echo 3 > /proc/sys/vm/drop_caches"'
- alias telegram="${HOME}/Downloads/bin/Telegram/Telegram"
- alias discord="${HOME}/Downloads/bin/Discord/Discord"
- alias tor-browser="${HOME}/Downloads/bin/tor-browser/Browser/start-tor-browser"
- alias tribler="${HOME}/Downloads/bin/tribler/src/tribler.sh"
- alias jdownloader="${HOME}/Downloads/bin/jd2/JDownloader2"
- alias read_log='journalctl -r'
- alias read_log2='dmesg -H'
- alias list_services='systemctl --all list-units'
- alias gedit='gnome-text-editor'
- alias su_gedit='sudo gnome-text-editor'
- alias irssi="irssi -c EFnet --config=${HOME}/.irssi2/config --home=~/.irssi2"
- alias is_wayland="echo $XDG_SESSION_TYPE"
- alias arch_pack='packer.sh a'
- alias arch_unpack='packer.sh x'
- alias arch_test='packer.sh t'
- alias arch_list='packer.sh l'
- alias stop_handbrake='stop_handbrake.sh'
- alias start_handbrake='start_handbrake.sh'
- alias stop_ffmpeg='sudo killall -20 ffmpeg'
- alias start_ffmpeg='sudo killall -18 ffmpeg'
- alias lower_volume='lower_volume_pw.sh'
- alias wine32="WINEPREFIX=${HOME}/.wine32 wine start /unix"
- alias wine32cfg="WINEARCH=win32 WINEPREFIX=${HOME}/.wine32 winecfg"
- alias redshift='redshift -l 57.70:11.97'
- alias wolf3d='wolf4sdl-registered-id --res 1600 1000'
- alias sod='wolf4sdl-spear --res 1600 1000'
- # alias quake='darkplaces-sdl -game quake15'
- alias quake='darkplaces-sdl'
- # alias prboom-plus='/usr/local/games/prboom-plus'
- alias rott='rott-registered fullscreen resolution 800x600'
- alias red_eclipse="${HOME}/SSD/redeclipse-1.6.0/redeclipse.sh"
- alias daikatana="${HOME}/SSD/Daikatana/start"
- alias doom64ex="${HOME}/SSD/doom64ex/doom64ex"
- # Declaring some regexes...
- declare no_ext ext
- declare -A regex
- regex[blank]='^[[:blank:]]*(.*)[[:blank:]]*$'
- regex[du]='^([[:digit:]]+)M([[:blank:]]+)(.*)$'
- regex[path]='^(.*[\\\/])(.*)$'
- regex[fn]='^(.*)\.([^.]*)$'
- regex[tar]='^\.tar\.[^.]*$'
- regex[dar]='^\.[[:digit:]]+\.dar$'
- regex[digit]='^[[:digit:]]+$'
- regex[720p]='\(([[:digit:]]{3,4})p_h\.264-aac\)'
- regex[1080p]='\(([[:digit:]]{3,4})p_([[:digit:]]{1,2})fps_(h264|av1)-([[:digit:]]{2,3})kbit_(aac|opus)\)'
- regex[scripts_backup]='scripts_[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}\.tar\.xz'
- regex[bin_backup]='bin_[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}\.tar\.xz'
- regex[opensub]='.*[[:alpha:]]{3}.[[:digit:]]cd.\([[:digit:]]+\)( \([[:digit:]]+\))*.zip'
- regex[date]='^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}$'
- regex[session]='^(.*)(-[[:digit:]]+){2}$'
- # Declaring some functions...
- mame () {
- declare cwd
- cwd="$PWD"
- cd "${HOME}/.mame"
- /usr/bin/mame
- cd "$cwd"
- }
- # Creates a function, called 'gzdoom', which will run the GZDoom
- # Flatpak (with arguments).
- gzdoom () {
- flatpak run org.zdoom.GZDoom "$@"
- }
- duke3d () {
- declare cwd
- cwd="$PWD"
- cd "${HOME}/SSD/eduke32/bin"
- ./eduke32
- cd "$cwd"
- }
- ignition () {
- declare cwd
- cwd="$PWD"
- cd "${HOME}/SSD/ignition"
- # wine 'ign_3dfx.exe'
- # ./start.sh
- dosbox -userconf -conf "dosbox_single.conf"
- cd "$cwd"
- }
- tmnt_palooza () {
- declare cwd
- cwd="$PWD"
- cd "${HOME}/SSD/TMNT Rescue-Palooza 1.1.1"
- wine 'TMNT_Rescue_Palooza.exe'
- cd "$cwd"
- }
- cube2 () {
- cd "${HOME}/SSD/sauerbraten"
- ./sauerbraten_unix
- }
- doom1 () {
- # sed --in-place 's/doom.*\.wad/doom.wad/'
- # ${HOME}/.prboom-plus/prboom-plus.cfg
- prboom-plus -iwad "${HOME}/Documents/DOOM/doom.wad"
- }
- doom2 () {
- # sed --in-place 's/doom.*\.wad/doom2.wad/'
- # ${HOME}/.prboom-plus/prboom-plus.cfg
- prboom-plus -iwad "${HOME}/Documents/DOOM/doom2.wad"
- }
- # Creates a function, called 'get_ext', which will separate file names
- # and extensions.
- get_ext () {
- declare -a ext_list
- declare -A input output
- input[fn]="$1"
- while [[ ${input[fn]} =~ ${regex[fn]} ]]; do
- no_ext="${BASH_REMATCH[1]}"
- ext_list=("${BASH_REMATCH[2],,}" "${ext_list[@]}")
- if [[ ${#ext_list[@]} -eq $2 ]]; then
- break
- fi
- done
- ext=$(printf '.%s' "${ext_list[@]}")
- }
- allupgrade () {
- sudo bash <<UPGRADE
- dnf --assumeyes --refresh --best upgrade
- dnf --assumeyes --best distro-sync
- dnf --assumeyes autoremove
- dnf --assumeyes clean all
- flatpak update --assumeyes
- UPGRADE
- }
- no_reboot () {
- sudo bash <<UPGRADE
- dnf --assumeyes --refresh --best --exclude="kernel*" --exclude="systemd*" upgrade
- dnf --assumeyes autoremove
- dnf --assumeyes clean all
- flatpak update --assumeyes
- systemctl daemon-reload
- UPGRADE
- }
- renice_pid () {
- declare pid
- if [[ ! $1 =~ ${regex[digit]} ]]; then
- return
- fi
- pid="$1"
- sudo bash <<RENICE
- renice -n -20 -p "$pid"
- RENICE
- }
- brktext () {
- tr '[:punct:]' ' ' <"$1" | tr '\n' ' ' | sed -E 's/[[:blank:]]+/ /g'
- }
- clntext () {
- tr -d '[:digit:]' <"$1" | sed -E -e 's/[[:blank:]]+/ /g' -e 's/^[[:blank:]]+//g' -e 's/[[:blank:]]+$//g'
- }
- searchtxt () {
- find "${HOME}/Documents" -iname "*.txt" 2>&- | while read txt; do grep -iH "$1" "$txt"; done
- }
- searchodt () {
- find "${HOME}/Documents" -iname "*.rtf" 2>&- | while read txt; do grep -iH "$1" "$txt"; done
- find "${HOME}/Documents" -iname "*.doc" 2>&- | while read txt; do grep -iH "$1" "$txt"; done
- find "${HOME}/Documents" -iname "*.odt" 2>&- | while read txt; do grep -iH "$1" "$txt"; done
- }
- find_cfg () {
- declare name
- declare -a names dirs files
- declare -A input output
- mapfile -t names < <(printf '%s\n' "${@,,}" | sort -u)
- mapfile -t dirs < <(find "$HOME" -mindepth 1 -maxdepth 1 -type d -iname ".*" 2>&-)
- for (( i = 0; i < ${#dirs[@]}; i++ )); do
- input[dn]="${dirs[${i}]}"
- for name in "${names[@]}"; do
- mapfile -t files < <(find "${input[dn]}" -iname "*${name}*" 2>&-)
- if [[ ${#files[@]} -gt 0 ]]; then
- printf '%s\n' "${files[@]}"
- fi
- done
- done | sort -u
- }
- find_old () {
- declare name date date_limit date_fn
- declare -a dirs files old
- declare -A input output
- if [[ $# -ne 3 ]]; then
- return
- fi
- if [[ ! -d $1 ]]; then
- return
- fi
- if [[ ! $3 =~ ${regex[date]} ]]; then
- return
- fi
- input[dn]=$(readlink -f "$1")
- name="$2"
- date="$3"
- date_limit=$(date --date="$date" '+%s')
- mapfile -t dirs < <(find "${input[dn]}" -mindepth 1 -maxdepth 1 -type d -iname "$name" 2>&-)
- for (( i = 0; i < ${#dirs[@]}; i++ )); do
- output[dn]="${dirs[${i}]}"
- mapfile -t files < <(find "${output[dn]}" -type f 2>&-)
- for (( j = 0; j < ${#files[@]}; j++ )); do
- output[fn]="${files[${j}]}"
- date_fn=$(stat -c '%Y' "${output[fn]}")
- if [[ $date_fn -lt $date_limit ]]; then
- old+=("${output[fn]}")
- fi
- done
- done
- printf '%s\n' "${old[@]}"
- }
- find_old_cfg () {
- find_old "$HOME" '.*' '2020-01-01'
- }
- find_double () {
- if [[ $# -ne 2 ]]; then
- return
- fi
- declare -A input output
- ls -1 "$1" | while read input[fn]; do
- input[bn]=$(basename "${input[fn]}")
- find "$2" -maxdepth 1 -name "${input[bn]}" 2>&-
- done
- }
- find_all () {
- if [[ $# -eq 0 ]]; then
- return
- fi
- declare cmd name names_str
- declare -a names
- for name in "$@"; do
- names+=( "\"$(sed -E 's/([[:blank:]])/\\\1/g' <<<"$name")\"" )
- done
- find_all_tmp () {
- for name in "$@"; do
- cmd=$(printf '%s\n' "find '/home' '/run/media' -iname \"${name}\"")
- eval "$cmd" 2>&-
- done
- }
- names_str="${names[@]}"
- sudo bash -c "$(declare -f find_all_tmp); find_all_tmp ${names_str}"
- }
- find_all_size () {
- declare line size
- declare -a files files_size
- declare -A input output
- mapfile -t files < <(find_all "$@")
- get_size () {
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- du -BM -s "${input[fn]}"
- done | sed -E "s/${regex[du]}/\1 \3/" | sort -rn
- }
- mapfile -t files_size < <(get_size)
- for (( i = 0; i < ${#files_size[@]}; i++ )); do
- line="${files_size[${i}]}"
- size="${line%% *}"
- input[fn]="${line#* }"
- printf '%s\n' "${input[fn]}"
- done
- }
- find_list () {
- if [[ ! -f $1 ]]; then
- return
- fi
- declare line
- while read line; do
- read -p "$pause_msg"
- find_all "$line"
- done <"$1"
- }
- find_meta () {
- find_all '.ds_store' 'thumbs.db'
- }
- find_trash () {
- sudo find '/home' '/run/media/' -maxdepth 3 -type d -iname ".trash*" 2>&-
- }
- find_root () {
- sudo find / \( -path '/home' -o -path '/run/media' -o -path '/proc' -o -path '/sys' \) -prune -o -iname "$1" -print 2>&-
- }
- find_root_recent () {
- declare session
- declare -a files
- declare -A input output
- session="${RANDOM}-${RANDOM}"
- output[bn]="${HOME}/find_recent_files"
- output[list_fn]="${output[bn]}_list-${session}.txt"
- output[size_fn]="${output[bn]}_size-${session}.txt"
- sudo find / \( -path '/home' -o -path '/run/media' -o -path '/proc' -o -path '/sys' \) -prune -o -type f -printf "%T@ %Tc %p\n" 2>&- | sort -n | cut -d' ' -f9- | tee "${output[list_fn]}"
- mapfile -t files <"${output[list_fn]}"
- touch "${output[size_fn]}"
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- sudo du -h "${input[fn]}" 2>&- | tee --append "${output[size_fn]}"
- done
- }
- find_movie_dups () {
- "${HOME}/bin/find_movie_dups.sh" "${HOME}" "/run/media/${USER}"
- }
- find_movie_dups_imdb () {
- "${HOME}/bin/find_movie_dups.sh" -imdb "${HOME}" "/run/media/${USER}"
- }
- find_shitrips () {
- declare line size
- declare -a files files_size
- declare -A input output
- output[fn]="${HOME}/shitrips.txt"
- mapfile -t files < <(find_all "*720p*" "*dvd*rip*" "*dvdscr*" "*screener*" "*divx*" "*xvid*")
- get_size () {
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- du -BM -s "${input[fn]}"
- done | sed -E "s/${regex[du]}/\1 \3/" | sort -rn
- }
- mapfile -t files_size < <(get_size)
- for (( i = 0; i < ${#files_size[@]}; i++ )); do
- line="${files_size[${i}]}"
- size="${line%% *}"
- input[fn]="${line#* }"
- input[bn]=$(basename "${input[fn]}")
- input[bn_lc]="${input[bn],,}"
- if [[ ${input[bn_lc]} =~ ${regex[720p]} || ${input[bn_lc]} =~ ${regex[1080p]} ]]; then
- continue
- fi
- printf '%s\n' "${input[fn]}"
- done | tee "${output[fn]}"
- }
- find_mkv_dups () {
- declare hash hash_ref
- declare -a files
- declare -A input output files_hash
- mapfile -t files < <(find_all "*.mkv" "*.mp4" "*.avi" "*.mpg" "*.mpeg")
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- get_ext "${input[fn]}" 1
- output[fn]="${no_ext}.mkv"
- hash=$(md5sum -b <<<"${output[fn]}")
- hash="${hash%% *}"
- hash_ref="files_hash[${hash}]"
- if [[ $ext != '.mkv' && -n ${!hash_ref} ]]; then
- printf '%s\n' '***'
- printf '%s\n' "${!hash_ref}"
- printf '%s\n' "${input[fn]}"
- fi
- if [[ $ext == '.mkv' && -z ${!hash_ref} ]]; then
- files_hash["${hash}"]="${input[fn]}"
- fi
- done
- }
- no_blank () {
- xset s off
- xset -dpms
- }
- run_wow () {
- WINEPREFIX="${HOME}/prefix32"
- WINEARCH=win32
- cd "/run/media/${USER}/0d6b70fa-0c49-47d6-84c1-3f8509d52b58/wow/WOW Wotlk 3.3.5a"
- wine 'Wow.exe'
- }
- restart_kde () {
- kquitapp5 plasmashell &&
- kstart5 plasmashell
- # sleep 10
- # kwin_x11 --replace &
- }
- compare_txt () {
- if [[ ! -f $1 || ! -f $2 ]]; then
- return
- fi
- declare line
- while read line; do grep -Fq "$line" "$2" || printf '%s\n' "$line"; done <"$1"
- }
- dnf_perl_install () {
- declare module
- for module in "$@"; do
- sudo dnf install "perl(${module})"
- done
- }
- update_dir () {
- if [[ ! -d $1 || ! -d $2 ]]; then
- return
- fi
- declare -A input output
- input[dn]="$1"
- output[dn]="$2"
- sudo rsync -Lacv --delete "${input[dn]}"/* "${output[dn]}"
- }
- update_flac () {
- declare -A input output
- input[dn]="${HOME}/Music/FLAC"
- output[dn]="/run/media/${USER}/SD_BTRFS/SD_BTRFS/Music/FLAC"
- update_dir "${input[dn]}" "${output[dn]}"
- }
- update_ps1 () {
- declare -a files
- declare -A input output
- input[dn]="/run/media/${USER}/2c5518a5-5311-4a7d-8356-206fecd9f13f/ROMs/playstation"
- output[dn]="/run/media/${USER}/SD_BTRFS/SD_BTRFS/playstation"
- if [[ ! -d ${input[dn]} || ! -d ${output[dn]} ]]; then
- return
- fi
- cd "${input[dn]}"
- mapfile -t files < <(compgen -G "*")
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- if [[ ${input[fn]} == 'unpacked' ]]; then
- continue
- fi
- read -p "$pause_msg"
- sudo rsync -Lacv --delete "${input[dn]}/${input[fn]}" "${output[dn]}"
- done
- }
- arch_test_tree () {
- if [[ ! -d $1 ]]; then
- return
- fi
- declare ext_tmp
- declare -a ext_list_tmp files
- declare -A input output
- input[dn]=$(readlink -f "$1")
- ext_list_tmp=('.dar' '.tar' '.z' '.gz' '.tgz' '.bz2' '.tbz' '.tbz2' '.txz' '.xz' '.zip' '.7z' '.rar' '.cab' '.lzh' '.lha' '.arj' '.iso')
- mapfile -t files < <(find "${input[dn]}" -type f 2>&-)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- get_ext "${input[fn]}" 1
- for ext_tmp in "${ext_list_tmp[@]}"; do
- if [[ $ext != "$ext_tmp" ]]; then
- continue
- fi
- arch_test "${input[fn]}"
- break
- done
- done
- }
- zip_2_7z () {
- declare cwd
- declare -a files
- declare -A input output
- cwd="$PWD"
- mapfile -t files < <(compgen -G "*.zip")
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- output[fn]="${input[fn]%.*}"
- mkdir "${output[fn]}"
- cd "${output[fn]}"
- arch_unpack ../"${input[fn]}" && rm ../"${input[fn]}"
- cd "$cwd"
- arch_pack "${output[fn]}.7z" "${output[fn]}" && rm -rf "${output[fn]}"
- done
- }
- sort_filetypes () {
- if [[ ! -d $1 ]]; then
- return
- fi
- declare type category
- declare -a types archives documents images media packages categories files
- declare -A input output
- input[dn]=$(readlink -f "$1")
- output[types_dn]="${input[dn]}/Filetypes"
- output[opensub_dn]="${output[types_dn]}/zip/opensubtitles"
- types=('7z' 'apk' 'avi' 'bz2' 'deb' 'doc' 'exe' 'flac' 'flv' 'gif' 'gz' 'img' 'iso' 'jpg' 'jpeg' 'mkv' 'mpg' 'mpeg' 'm3u' 'mov' 'mp3' 'mp4' 'odt' 'ogg' 'pdf' 'pls' 'png' 'rar' 'rpm' 'rtf' 'srt' 'svg' 'tar' 'torrent' 'txt' 'wav' 'webm' 'xcf' 'zip' 'xspf' 'xz')
- archives=('7z' 'bz2' 'gz' 'rar' 'tar' 'zip' 'xz')
- documents=('doc' 'odt' 'pdf' 'rtf' 'txt')
- images=('gif' 'jpg' 'jpeg' 'png' 'svg' 'xcf')
- media=('avi' 'flac' 'flv' 'mkv' 'mpg' 'mpeg' 'mov' 'mp3' 'mp4' 'ogg' 'wav' 'webm')
- packages=('apk' 'deb' 'rpm')
- categories=('archives' 'documents' 'images' 'media' 'packages')
- categorize () {
- output[dn]="${output[types_dn]}/${category}/${type}"
- mapfile -t files < <(find "${output[types_dn]}/${type}" -maxdepth 1 -type f 2>&-)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- mkdir -p "${output[dn]}"
- mv -n "${input[fn]}" "${output[dn]}"
- done
- }
- mkdir -p "${input[dn]}"
- mapfile -t files < <(find "${input[dn]}" -maxdepth 1 -type f 2>&-)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- get_ext "${input[fn]}" 1
- for type in "${types[@]}"; do
- if [[ $ext != ".${type}" ]]; then
- continue
- fi
- output[dn]="${output[types_dn]}/${type}"
- mkdir -p "${output[dn]}"
- mv -n "${input[fn]}" "${output[dn]}"
- break
- done
- done
- mkdir -p "${output[types_dn]}/jpg" "${output[types_dn]}/mpg"
- mv -n "${output[types_dn]}/jpeg"/* "${output[types_dn]}/jpg"
- mv -n "${output[types_dn]}/mpeg"/* "${output[types_dn]}/mpg"
- for category in "${categories[@]}"; do
- mkdir -p "${output[types_dn]}/${category}"
- case $category in
- 'archives')
- for type in "${archives[@]}"; do
- categorize
- done
- ;;
- 'documents')
- for type in "${documents[@]}"; do
- categorize
- done
- ;;
- 'images')
- for type in "${images[@]}"; do
- categorize
- done
- ;;
- 'media')
- for type in "${media[@]}"; do
- categorize
- done
- ;;
- 'packages')
- for type in "${packages[@]}"; do
- categorize
- done
- ;;
- esac
- done
- mapfile -t files < <(find "${output[types_dn]}/archives/zip" -maxdepth 1 -type f 2>&-)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- if [[ ! ${input[fn]} =~ ${regex[opensub]} ]]; then
- continue
- fi
- mkdir -p "${output[opensub_dn]}"
- mv -n "${input[fn]}" "${output[opensub_dn]}"
- done
- rm_empty_dirs "${output[types_dn]}"
- }
- recursive_extract () {
- if [[ ! -d $1 ]]; then
- return
- fi
- declare ext_tmp
- declare -a ext_list_tmp files
- declare -A input output
- input[dn]=$(readlink -f "$1")
- cd "${input[dn]}"
- ext_list_tmp=('.dar' '.tar' '.z' '.gz' '.tgz' '.bz2' '.tbz' '.tbz2' '.txz' '.xz' '.zip' '.7z' '.rar' '.cab' '.lzh' '.lha' '.arj')
- mapfile -t files < <(find "${input[dn]}" -type f 2>&-)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- input[bn]=$(basename "${input[fn]}")
- get_ext "${input[fn]}" 1
- for ext_tmp in "${ext_list_tmp[@]}"; do
- if [[ $ext != "$ext_tmp" ]]; then
- continue
- fi
- output[dn]="${no_ext}-${RANDOM}-${RANDOM}"
- mkdir -p "${output[dn]}"
- mv "${input[fn]}" "${output[dn]}"
- cd "${output[dn]}"
- arch_unpack "${input[bn]}"
- if [[ $? -eq 0 && -f ${input[bn]} ]]; then
- rm -f "${input[bn]}"
- fi
- cd "${input[dn]}"
- break
- done
- done
- }
- rm_empty_dirs () {
- if [[ ! -d $1 ]]; then
- return
- fi
- declare -a dirs
- declare -A input output
- input[dn]=$(readlink -f "$1")
- mapfile -t dirs < <(find "${input[dn]}" -type d -empty 2>&-)
- until [[ ${#dirs[@]} -eq 0 ]]; do
- for (( i = 0; i < ${#dirs[@]}; i++ )); do
- output[dn]="${dirs[${i}]}"
- rm -rf "${output[dn]}"
- done
- mapfile -t dirs < <(find "${input[dn]}" -type d -empty 2>&-)
- done
- }
- rm_empty_files () {
- if [[ ! -d $1 ]]; then
- return
- fi
- declare size
- declare -a files
- declare -A input output
- input[dn]=$(readlink -f "$1")
- mapfile -t files < <(find "${input[dn]}" -type f 2>&-)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- size=$(stat -c '%s' "${input[fn]}")
- if [[ $size -eq 0 ]]; then
- rm -f "${input[fn]}"
- fi
- done
- }
- flatten_dn () {
- if [[ ! -d $1 ]]; then
- return
- fi
- declare -a files
- declare -A input output
- input[dn]=$(readlink -f "$1")
- mapfile -t files < <(find "${input[dn]}" -type f 2>&-)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- mv -n "${input[fn]}" "${input[dn]}"
- done
- rm_empty_dirs "${input[dn]}"
- }
- unique_ext () {
- if [[ ! -d $1 ]]; then
- return
- fi
- declare -a files
- declare -A input output
- input[dn]=$(readlink -f "$1")
- mapfile -t files < <(find "${input[dn]}" -maxdepth 1 -type f 2>&-)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- if [[ ${input[fn]} =~ ${regex[fn]} ]]; then
- printf '%s\n' "${BASH_REMATCH[2]}"
- fi
- done | sort -u
- }
- unique_type () {
- if [[ ! -d $1 ]]; then
- return
- fi
- declare info
- declare -a files
- declare -A input output
- input[dn]=$(readlink -f "$1")
- mapfile -t files < <(find "${input[dn]}" -maxdepth 1 -type f 2>&-)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- info=$(file -b "${input[fn]}")
- printf '%s\n' "${info%%:*}"
- done | sort -u
- }
- lc_ext () {
- if [[ ! -d $1 ]]; then
- return
- fi
- declare -a files
- declare -A input output
- input[dn]=$(readlink -f "$1")
- mapfile -t files < <(find "${input[dn]}" -maxdepth 1 -type f 2>&-)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- get_ext "${input[fn]}" 1
- output[fn]="${no_ext}${ext}"
- if [[ ${input[fn]} != "${output[fn]}" ]]; then
- mv -n "${input[fn]}" "${output[fn]}"
- fi
- done
- }
- fn2md5 () {
- if [[ ! -d $1 ]]; then
- return
- fi
- declare hash
- declare -a files
- declare -A input output
- input[dn]=$(readlink -f "$1")
- mapfile -t files < <(find "${input[dn]}" -maxdepth 1 -type f 2>&-)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- get_ext "${input[fn]}" 1
- hash=$(md5sum -b "${input[fn]}")
- hash="${hash%% *}"
- mv -n "${input[fn]}" "${hash}${ext}"
- done
- }
- git_link () {
- declare cwd local_bin git_repo script
- cwd="$PWD"
- local_bin="${HOME}/bin"
- git_repo="${local_bin}/git_repo"
- cd "${local_bin}/git_repo"
- while [[ $@ ]]; do
- script="${local_bin}/${1}"
- if [[ -f $script && ! -f $1 && ! -L $1 ]]; then
- printf '%s\n' "Link created: ${script}"
- ln ../"${1}" "${1}"
- fi
- shift
- done
- cd "$cwd"
- }
- git_push () {
- declare cwd local_bin git_repo
- cwd="$PWD"
- local_bin="${HOME}/bin"
- git_repo="${local_bin}/git_repo"
- cd "${local_bin}/git_repo"
- git add . && git commit -m "${1}"
- git push origin main
- cd "$cwd"
- }
- scripts_backup () {
- declare date
- declare -a files
- declare -A input output
- date=$(date '+%F')
- output[fn]="scripts_${date}.tar.xz"
- output[dn]="/run/media/${USER}/0d6b70fa-0c49-47d6-84c1-3f8509d52b58"
- rm_old () {
- mapfile -t files < <(find "$1" -maxdepth 1 -type f -iname "scripts_*.tar.xz*" 2>&-)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- input[bn]=$(basename "${input[fn]}")
- if [[ ${input[bn]} =~ ${regex[scripts_backup]} ]]; then
- rm -f "${input[fn]}"
- fi
- done
- }
- rm_old "$HOME"
- rm_old "${output[dn]}"
- cd "$HOME"
- arch_pack "${output[fn]}" bin
- md5sum -b "${output[fn]}" | tee "${output[fn]}.md5"
- cp -p "${output[fn]}"* "${output[dn]}"
- sync
- }
- sort_bin_archive () {
- declare date
- declare -a files
- declare -A input output
- input[bin_dn]="${HOME}/bin"
- input[archive_dn]="${input[bin_dn]}/archive"
- if [[ ! -d ${input[archive_dn]} ]]; then
- return
- fi
- rm_md5sum.pl "${input[archive_dn]}"
- mapfile -t files < <(find "${input[archive_dn]}" -type f -iname "*.sh" -o -iname "*.pl" -o -iname "*.php" 2>&-)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- date=$(stat -c '%y' "${input[fn]}")
- date="${date%% *}"
- output[fn]="${input[fn]}.${date}"
- sudo "${input[bin_dn]}/reformat_script.sh" "${input[fn]}"
- sudo "${input[bin_dn]}/reformat_script.sh" "${input[fn]}"
- printf '%s\n' "${output[fn]}"
- mv -n "${input[fn]}" "${output[fn]}"
- done
- # flatten_dn "${input[archive_dn]}"
- }
- kill_gnome () {
- declare comm pid
- declare -a pids
- comm='/usr/libexec/xdg-desktop-portal-gnome'
- mapfile -t pids < <(pgrep -xf "$comm")
- for (( i = 0; i < ${#pids[@]}; i++ )); do
- pid="${pids[${i}]}"
- sudo kill -15 "$pid"
- done
- sleep 1
- killall -15 'gnome-shell'
- }
- temp_sensor_files () {
- declare -A input output
- while [[ 1 ]]; do
- clear
- for input[fn] in /sys/class/hwmon/hwmon*/temp*_input; do
- echo "* ${input[fn]}"
- cat "${input[fn]}"
- echo
- done
- sleep 1
- done
- }
- is_game_in_ram () {
- declare -a files
- declare -A input output
- regex[game2ram]='^game2ram(-[[:digit:]]+){2}'
- mapfile -t files < <(ls -1 -t /dev/shm/)
- for (( i = 0; i < ${#files[@]}; i++ )); do
- input[fn]="${files[${i}]}"
- if [[ ${input[fn]} =~ ${regex[game2ram]} ]]; then
- output[fn]="${input[fn]}"
- break
- fi
- done
- if [[ -z ${output[fn]} ]]; then
- return
- fi
- lsof +D "/dev/shm/${output[fn]}"
- }
- update_bashrc () {
- sudo cp -p /home/lucifer/bashrc /home/lucifer/.bashrc
- sudo chown root:root /home/lucifer/.bashrc
- }
Add Comment
Please, Sign In to add comment