Skip to content

πŸŽ‰πŸ•ΊπŸ’ƒπŸŽŠ Keep the party alive with these Bash configurations and scripts. An optimized environment for effortless workflow and versioning.

License

Notifications You must be signed in to change notification settings

apple-fritter/celebration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŽ‰πŸ•ΊπŸ’ƒπŸŽŠ celebration

Discover how a properly formatted workspace can help you unleash your creative potential and bring your ideas to life with optimized configurations and scripts. Streamline your workflow, reduce errors, and create with ease by trying them out today.


.bashrc Files

The .bashrc files in this project improve your experience and productivity when working in the BASH shell.


Features

Notable features include a visually appealing divider displaying the time and date stamp between prompts, which enhances the shell's appearance and aids in debugging:

Source

PROMPT_COMMAND='separator'

# Prompt command to print a graphical divider with time and date stamp between shell prompts.
function separator() {
    local datestring=$(date +"%Y%m%d, %A")
    local timestring=$(date +"%H:%M:%S")
    local separator_length=$(tput cols)
    local date_length=${#datestring}
    local time_length=${#timestring}
    local space_length=$((separator_length - date_length - time_length - 8))

    if (( space_length < 0 )); then
        space_length=0
    fi

    # Calculate the actual line length excluding the borders
    local line_content_length=$((date_length + space_length + time_length + 4))  # 4 for " β”‚ "
    
    # Create the top and bottom lines based on content length
    local line_top="β”Œ$(printf "%-$((separator_length - 2))s" "" | tr ' ' ' ')┐"
    local line_bottom="β””$(printf "%-$((separator_length - 2))s" "" | tr ' ' ' ')β”˜"

    # Construct the middle line
    local line_middle="β”‚ $(printf " %s %${space_length}s %s " "$datestring" "" "$timestring") β”‚"

    # Print the lines with colors
    printf "\e[1;34m%s\e[0m\n" "$line_top"
    printf "\e[1;37m%s\e[0m\n" "$line_middle"
    printf "\e[1;34m%s\e[0m\n" "$line_bottom"
}

Example Output

β”Œ                                                                              ┐
β”‚  20230925, Monday                                                    153648  β”‚
β””                                                                              β”˜

Screenshot

Screenshot_2024-10-24_10-37-13
The pictured .conkyrc file can be found at https://github.com/apple-fritter/.conkyrc.

Separator Explained

This separator function creates a visually appealing separator line in a terminal that displays the current date and time, formatted in a specific way. Here’s a breakdown of how it works:

  1. Date and Time Retrieval:

    • It fetches the current date in the format YYYYMMDD, DayOfWeek and the current time in HH:MM:SS format.
  2. Terminal Width Calculation:

    • It determines the width of the terminal using tput cols to create a dynamic separator that fits the screen.
  3. Space Calculation:

    • It calculates the space needed between the date and time based on the terminal width, accounting for the lengths of the date and time strings, as well as some extra characters for borders and padding.
  4. Handling Short Widths:

    • If the calculated space is negative (meaning there’s not enough room), it sets the space to zero to avoid errors.
  5. Line Construction:

    • It constructs the top and bottom borders using β”Œ and β””, filling the space in between with spaces.
    • The middle line combines the date and time with appropriate spacing and is framed by vertical bars (β”‚).
  6. Color Formatting:

    • The top and bottom lines are printed in blue, and the middle line (which contains the date and time) is printed in white, using ANSI escape codes for color.
  7. Output:

    • Finally, it prints the three lines to create a boxed effect around the current date and time.

This function provides a nice visual separator for output in a terminal, making it easy to read the current date and time at a glance.


Prompt levels

PS1 and PS2 have been defined, enhancing the prompt's appearance.

PS1='\n\u@\h\n[\w]\n'
PS2='\n β–“β–’β–‘ '

PS1='\n\u@\h\n[\w]\n' sets the prompt to display the username , hostname, and current working directory, with a newline to form the prompt:

GitHubFAN23@macbookpro
[~/Downloads]
Prompt text goes here_

PS2='\n β–“β–’β–‘ ' sets the secondary prompt to show a pattern of block characters. This prompt level provides visual indication that more input is expected.


These files also comprise various settings and aliases that streamline frequently used commands, making them more efficient while the history command and history ignoring commands' format have been tailored to enhance productivity, and they includes aliases for referencing system management shell scripts also provided in this repository.

Establish the time format for long-running commands
export TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n'
Progress bar for dd!

This alias includes the status=progress option, which provides real-time information on the transfer speed, amount of data transferred, and estimated time remaining.

alias dd='dd status=progress'
Provide aliases for disk usage and space
alias du='du -kh'
alias df='df -kTh'
Show files with color and long format
alias ls='ls -aclX --color'
Create an alias to notify users when a long-running command completes
alias alert='notify-send --urgency=low \
  -i "$([ $? = 0 ] && echo terminal || echo error)" \
  "$(history | tail -n1 | sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'' )"'
Specify default wget arguments
To appear as a web browser request, supporting download resumes
alias wget='wget -c --user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"'
To easily mirror(scrape) a website
alias wgetmirror='wget --mirror \
  --convert-links \
  --adjust-extension \
  --page-requisites \
  --no-parent \
  -c \
  -w 2.2 \
  -e robots=off \
  --no-check-certificate \
  --user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"'

Scripts:

Superuser scripts:

Executes a sequence of cleanup tasks to optimize system performance. It scans for all schema files that are not utilized by any installed applications and removes them to free up space.

THE SCHEMA CLEANER HAS BEEN DISABLED until it is reliable.

β”Œβ”€ Start Script
β”‚
===============[BEGIN BROKEN SECTION]
β”œβ”€ Check if the schema directory exists
β”‚   β”œβ”€ Directory doesn't exist
β”‚   β”‚       └─ Display "Directory <schema_dir> not found." and exit
β”‚   └─ Continue to next step
β”‚
β”œβ”€ Find unused schema files
β”‚   β”œβ”€ Find all schema files in <schema_dir> that are not referenced by installed applications, utilizing gsettings
β”‚   └─ Store list of unused schema files in UNUSED_SCHEMAS
β”‚
β”œβ”€ Remove unused schema files
β”‚   β”œβ”€ Loop for each schema in UNUSED_SCHEMAS
β”‚   β”‚       β”œβ”€ Remove the schema file
β”‚   β”‚       └─ Display "Removed <schema_file>"
β”‚   └─ Compile the remaining schema files
β”‚
β”œβ”€ Compile schemas
β”‚   β”œβ”€ Compile the remaining schema files in <schema_dir> using glib-compile-schemas command
β”‚   └─ Binary cache files for the schemas are generated
=================[END BROKEN SECTION]
β”œβ”€ Clean up
β”‚   β”œβ”€ bash history
β”‚   β”œβ”€ backup files
β”‚   β”œβ”€ DS_Store files
β”‚   β”œβ”€ Thumbs.db files
β”‚   β”œβ”€ tmp files
β”‚   β”œβ”€ Java cache
β”‚   β”œβ”€ SQLite3 history
β”‚   β”œβ”€ system cache
β”‚   β”œβ”€ rotated logs
β”‚   β”œβ”€ trash
β”‚   β”œβ”€ thumbnail cache
β”‚   └─ X11 debug logs
β”‚
β”œβ”€ Remove packages that are no longer needed
β”œβ”€ Clear the local package cache
└─ End Script

Automates the process of updating all installed software packages on your system. By running the script from a root prompt, it will automatically search for and install any available updates. This saves time and effort while also keeping your system secure and up-to-date.

β”Œβ”€ Start Script
β”‚
β”œβ”€ Run apt-get update command
β”‚     └─ Automatically answer "yes" to any prompts
β”‚
β”œβ”€ Run apt-get dist-upgrade command
β”‚     └─ Automatically answer "yes" to any prompts
β”‚
└─ End Script

Regular User Scripts:

Optimizes system performance by rebuilding the Mozilla Firefox configuration from scratch using a backup skeleton, if available. The script also cleans up various files and directories that tend to accumulate over time and occupy valuable storage space.

β”Œβ”€ Start Script
β”‚
β”œβ”€ Set working directory to the user's home
β”‚
β”œβ”€ Home Directory Cleanup
β”‚  β”œβ”€ Remove ~/.cache/ and ~/.android/
β”‚  └─ Remove specific files: .xsession-errors*, .wget-hsts, .bash_history, .sudo_as_admin_successful
β”‚
β”œβ”€ Rebuild Browser Configuration
β”‚  β”œβ”€ Remove browser config directories: ~/.config/BraveSoftware, ~/.config/chromium, ~/.mozilla/
β”‚  └─ Rebuild browser config from skeleton file (browser-skel.7z)
β”‚
β”œβ”€ Clean Up Backup Files
β”‚  └─ Delete files with .bak extension
β”‚
β”œβ”€ Clean Up DS_Store Files
β”‚  └─ Delete .DS_Store files
β”‚
β”œβ”€ Clean Up Thumbs.db Files
β”‚  └─ Delete Thumbs.db files
β”‚
β”œβ”€ Clean Up tmp Files
β”‚  └─ Delete files with .tmp extension
β”‚
β”œβ”€ Remove Editor Cruft
β”‚  └─ Remove editor config directories: ~/.config/geany/, ~/.config/Code/, ~/.config/featherpad/, ~/.vscode
β”‚
β”œβ”€ Clean Up Desktop Entry Files
β”‚  └─ Delete .desktop files in ~/.local/share/applications/
β”‚
└─ Clean Up Trash
   └─ Delete contents of ~/.local/share/Trash/

This script retrieves a list of installed packages on a Debian-based system and saves the package names along with their versions to a tab separated text file, located in the user's Documents directory ~/Documents

Common Scripts

Sorts a text file alphabetically and eliminates duplicated lines, saving time and effort while ensuring data accuracy and integrity.

β”Œβ”€ Start Script
β”‚
β”œβ”€ Sort the contents of file <input_file>
β”‚     └─ Store the sorted output in a temporary file <input_file>.tmp
β”‚
β”œβ”€ Remove duplicate lines from the sorted output
β”‚     └─ Store the unique lines in the temporary file <input_file>.tmp
β”‚
β”œβ”€ Rename the temporary file <input_file>.tmp to <input_file>
β”‚
└─ End Script

This script is a bash shell script designed to convert text files from DOS/Windows line endings CRLF - Carriage Return Line Feed to Unix line endings LF - Line Feed. When you run this script with a folder path as an argument or without any argument, it will convert all the text files in that folder and its subfolders from DOS/Windows line endings to Unix line endings using the dos2unix command. This is useful when you have files that were created or edited on Windows systems and need to be used on Unix-based systems.

The run_dos2unix_recursive function is defined to handle the recursive conversion of files in subfolders. It takes one argument, which is the folder path to be processed.

  • It loops over all files and folders within the provided folder path using the for loop.
  • If the current item in the loop is a subfolder (directory), the function calls itself run_dos2unix_recursive recursively to process files within that subfolder.
  • If the current item is a regular file, it uses the dos2unix command to convert the file's line endings from DOS/Windows format to Unix format.

The main function is defined to handle the execution of the script.

  • It checks if any command-line arguments are provided using $# -eq 0. If no arguments are provided, it sets the folder_path variable to the current working directory using $(pwd). If an argument is provided, it uses that as the folder_path. Finally, the main function is called with the provided command-line arguments main "$@".
β”Œβ”€ Start Script
β”‚
β”œβ”€ Check if command-line arguments are provided
β”‚     β”œβ”€ No arguments provided:
β”‚     β”‚  β”‚
β”‚     β”‚  └─ Set folder_path to the current working directory ($(pwd))
β”‚     β”‚
β”‚     └─ Arguments provided
β”‚        └─ Set folder_path to the provided argument
β”‚
β”œβ”€ Call the run_dos2unix_recursive() function with folder_path
β”‚
└─ End Script

Quickly fills a target file with a specified input pattern, making it useful for generating large amounts of sample data for testing or demonstration purposes.

β”Œβ”€ Start Script
β”‚
β”œβ”€ Define input_file and output_file variables from command line arguments
β”‚     └─ Assign the value of the first command line argument to input_file
β”‚     └─ Assign the value of the second command line argument to output_file
β”‚
β”œβ”€ Check if either input_file or output_file is empty
β”‚     β”œβ”€ If either file is empty
β”‚     β”‚     └─ Prompt user for input file path
β”‚     β”‚     └─ Prompt user for output file path
β”‚     └─ If both input_file and output_file are provided
β”‚           └─ Check if the number of arguments is greater than 2
β”‚                 └─ Display an error message to stderr
β”‚                 └─ Exit the script with status code 1
β”‚
β”œβ”€ Use a while loop to continuously append input_file contents to output_file
β”‚     └─ Append the contents of input_file to output_file
β”‚
└─ End Script

The while loop continuously appends the contents of the input file to the output file indefinitely, which may result in an infinite loop. You may want to consider adding a condition or an exit condition within the loop to ensure it doesn't run indefinitely.





This software is provided "as is" and without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

The authors do not endorse or support any harmful or malicious activities that may be carried out with the software. It is the user's responsibility to ensure that their use of the software complies with all applicable laws and regulations.


License

These files released under the MIT License.

About

πŸŽ‰πŸ•ΊπŸ’ƒπŸŽŠ Keep the party alive with these Bash configurations and scripts. An optimized environment for effortless workflow and versioning.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages