Skip to main content

Get the Reddit app

Scan this QR code to download the app now
Or check it out in the app stores

r/shell

members
online


Bash: Animation missing only in dedicated terminal Bash: Animation missing only in dedicated terminal

hey guys.

i cant find a solution of what this is or what i did that causes this but here's a small explanation.

i wrote a node CLI with npm package "prompts" but switched to "@inquirer/prompts". (for testing purpose i wrote another small CLI for choosing colors). before i switched the animation to choose per arrow keys in a "select" prompt stopped working in a dedicated Bash Terminal. (it just stopped working after for like 1-2 months). the choices still go through just the animation does not change. even with the new package it shows no animation letting me suspect its not the npm packages.

the weird thing is, this works in every other terminal/shell like cmd, powershell. and the most peculiar is using the same bash terminal in vs code shows no problem and the animation is working fine.

i tried using another theme, font, different terminal types like xterm and co, deleted .bash_profile & .bashrc, resetting the terminal itself, reinstall git+bash.

nothing in the options i see is anything close to animations.

bash is v5.2.26 using mintty 3.7.1 on windows 10

any help is appreciated and if you need more info just tell me. thank you so far for reading.



Zip contents of a directory excluding the directory Zip contents of a directory excluding the directory

Hello, I am new to scripting and trying to make a script that will make it easier to use yuescript to code with the love2d framework. I am currently facing an issue with the zip command.

yue -t lua src
rm game.love
zip -r game.love lua
love game.love

The probem is that the root is lua directory and not main.lua, using lua/* doesn't seem to work, the rest works as intended


etcsh: an enhanced version of the original tcsh etcsh: an enhanced version of the original tcsh

etcsh is an enhanced version of the original tcsh, which is a version of the original Berkeley C shell implementing file name completion and command line editing.

etcsh features the following enhancements and fixes over the original tcsh.

• Function declarations;

• variable assignment from pipes and redirections;

• comments on interactive sessions;

• tell whether stdin is empty or not;

• variable expansion on expressions corrected;

• piped built-ins are forked;

• missing test built-in implemented;

• read-write variable flag;

exit shall cancel lists.

More is to come. Feedbacks and contributions are much appreciated.


Shameless plug: pieshell: python for shell scripting and as an interactive shell Shameless plug: pieshell: python for shell scripting and as an interactive shell

I have written a shell that uses the Python language as the scripting language: it's a shell environment that combines the expressiveness of shell pipelines with the power of python iterators.

It can be used in two major ways:

  • As an interactive shell replacing e.g. bash

  • As an ordinary python module replacing e.g. subprocess.Popen

Obligatory example:

140:/home/redhog/Projects/beta/pieshell >>> for x in ls(-a):
...   if x.endswith('.py'):
...      print x
... 
setup.py

https://github.com/redhog/pieshell







please explain this please explain this

hello

https://github.com/MonkeyWearingAFezWithAMop/UnityBuild-Upload/blob/main/install_butler.sh

I was trying to work out how to install butler for itch.io

https://itch.io/docs/butler/installing.html

but got stuck trying to "add butler to path" (whatever that means)

I asked chatgpt to write a script to do this and it made this and it seemed to work...

can anyone explain what "adding to path" means?

and what exactly was I supposed to do once I got to this step in the instructions

I was using a macbook pro if that makes any difference to you explanation?

thanks



Shell Script - Skipping over files to process Shell Script - Skipping over files to process

I am trying to process multiple files present in a folder. My requirement is to process ALL the files but at max 15 in parallel. I wrote the below script to achieve the same.

However, this isn't working as expected. This script is processing all the files in the firs iteration (i.e. 15 in this case) but once the first 15 are done, it's processing alternate files. Thus if a folder has say 27 files, it's processing all the first 15 and then 6 of the remaining 12.

What am I doing wrong and how can I correct it?

#!/bin/bash

# Path to the folder containing the files
INPUT_FILES_FOLDER="/mnt/data/INPUT"
OUTPUT_FILES_FOLDER="/mnt/data/OUTPUT"

# Path to the Docker image
DOCKER_IMAGE="your_docker_image"

# Number of parallel instances of Docker to run
MAX_PARALLEL=15

# Counter for the number of parallel instances
CURRENT_PARALLEL=0

# Function to process files
process_files() {
    for file in "$INPUT_FILES_FOLDER"/*; do
	input_file=`basename $file` 
	output_file="PROCESSED_${input_file}"

	input_folder_file="/data/INPUT/${input_file}"
	output_folder_file="/data/OUTPUT/${output_file}"

	echo "Input File: $input_file"
	echo "Output File: $output_file"

	echo "Input Folder + File: $input_folder_file"
	echo "Output Folder + File: $output_folder_file"


        # Check if the current number of parallel instances is less than the maximum allowed
        if [ "$CURRENT_PARALLEL" -lt "$MAX_PARALLEL" ]; then
            # Increment the counter for the number of parallel instances
            ((CURRENT_PARALLEL++))
            
            # Run Docker container in the background, passing the file as input
	    # docker run hello-world
	    docker run --rm -v /mnt/data/:/data my-docker-image:v5.1.0 -i $input_folder_file -o $output_folder_file &
            
            # Print a message indicating the file is being processed
            # echo "Processing $file"
        else
            # If the maximum number of parallel instances is reached, wait for one to finish
            wait -n && ((CURRENT_PARALLEL--))
        fi
    done
    
    # Wait for all remaining Docker instances to finish
    wait
}

# Call the function to process files
process_files




Expanding variable as command line parameters causes single quotes round strings Expanding variable as command line parameters causes single quotes round strings

I am trying to place the string contents of a shell variable into a command as arguments. When bash expands the variable it places single quotes around elements of the string.

#!/bin/bash

LOGFILE="/var/log/autprestic.log
AUTORESTIC_CONFIG="/home/xxxx/.autorestic.yml"
RESTIC_PARAMS="--ci 2>&1 >> $LOGFILE"

$(which autorestic) -c $AUTORESTIC_CONFIG backup -a ${RESTIC_PARAMS}

Results in:

/usr/local/bin/autorestic -c /home/xxxx/.autorestic.yml backup -a --ci '2>&1' '>>' /var/log/autorestic.log

Why do the expanded parameters have single quotes around them?


solv-sh :: Soulver-like Bash Script designed for Vim solv-sh :: Soulver-like Bash Script designed for Vim

Although this is a Bash Script I wrote it deliberately to give myself a Soulver-like experience in my Vim notes system so I hope it's okay to post here:

Essentially it tries to strip anything from its input that would upset bc and uses that to find an answer to each line:

a simple sum 1 + 1                          #= 2
let us multiply that result LINE:-1 * 3     #= 6
and sum the previous lines SUM:-2,-1        #= 8
as a percentage demo 2 - 1 as % of LINE:+2  #= 3.90625
percent off demo (5 * 2) % off 512          #= 460.8
percent of demo 10 % of 256                 #= 25.6

Answers appear to the right of the #= and will be stripped and recalculated if you send the script a sequence of lines that already include them.

Different to Soulver, I opted to use relative line-numbers for the LINE: and SUM: tokens to make things more natural to the Vim experience: So LINE:+5 means replace that token with the answer calculated 5 lines ahead, and SUM:-3,-1 means replace that token with the sum of the previous 3 lines.

As you can see, it permits arbitrary strings before expressions (and after too) so you can annotate them, but it's not very clever so don't expect it to do the right thing with a bunch of punctuation.

Hope others find it useful!

upvotes


Question about starship prompt Question about starship prompt

I am transitioning from Powerlevel10K to the starship prompt. The benefits are clear - much faster load and response time and (sry, that's just plainly wrong) significantly cleaner configuration.

However there is a crucial feature I'm missing: in P10K when I would start to type a kubectl command, it would automatically display the k8s context. How can I get such a behavior in starship? It appears that I can only configure the kubernetes module to trigger based on files and directories. Any help appreciated!


Shell script to convert PNGs to ICNS Shell script to convert PNGs to ICNS

Hi all,

I am trying to get the following script found here to work in the Apple Shortcuts app:

#!/bin/sh

s=$1

ICON_NAME="${s%.*}.icns"

echo "Converting $1 to $ICON_NAME..."

# Create an icon directory to work in

ICONS_DIR="tempicon.iconset"

mkdir $ICONS_DIR

# Create all other images sizes

sips -z 1024 1024 $1 --out "$ICONS_DIR/icon_512x512@2x.png"

sips -z 512 512 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_512x512.png"

sips -z 512 512 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_256x256@2x.png"

sips -z 256 256 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_256x256x.png"

sips -z 256 256 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_128x128@2x.png"

sips -z 128 128 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_128x128.png"

sips -z 64 64 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_64x64.png"

sips -z 32 32 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_32x32.png"

sips -z 32 32 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_16x16@2x.png"

sips -z 16 16 "$ICONS_DIR/icon_512x512@2x.png" --out "$ICONS_DIR/icon_16x16.png"

# Create the icns file

iconutil -c icns $ICONS_DIR

# remove the temporary directory

rm -rf $ICONS_DIR

# rename icns

mv tempicon.icns $ICON_NAME

I added the shortcut to Quick Actions so that I can just right-click PNGs anywhere on my system and create an ICNS file in the same directly/folder where the PNG is located, but I get the following error message for every image size the script tries to create:

error: Warning: tempicon.iconset/icon_512x512@2x.png not a valid file - skipping

Does anyone know how to fix?

Thanks


How can i add a line counter to my script to indicate progress? How can i add a line counter to my script to indicate progress?

read -p " Is this correct ? (yes/no) " CONT
if [ "$CONT" = "yes" ] || [ "$CONT" = "y" ] || [ "CONT" = "Yes" ]; then
echo ---------------------------------------------------------------
echo "Deleting keys .... "
while read -r line;
do
[[ -n "$line" ]] && yes | eval "confluent api-key delete $line" $OPTIONS;
echo "Key: $line Status: DELETED"
done < "prod/env/$CLIENT_FILE"
echo "Searching for $line..."
eval "confluent api-key list | grep $CLIENT_FILE "
echo ---------------------------------------------------------------------------
echo "Complete.. Exiting.."

else
echo " Exiting.....";
fi

Regarding the code above, how can i add a counter for each line. I have a deployment to delete api keys that are listed in a file and i can get it to tell me how many api keys are in the file but what is the best way to count each line as it runs for a progress indicator?

I want the output to be something like

(1) Key: ASDFWERTDCGVTRYUERT Status: DELETED"

(2) Key: HJSDH38FG4929FH43921 Status: DELETED"


Creating Command-Line Tools in Python (with argspace): A Practical Guide Creating Command-Line Tools in Python (with argspace): A Practical Guide

The guide explores how Python command-line tools provide a convenient way to automate repetitive tasks, script complex work as well as some examples of how argparse (a standard Python library for parsing command-line arguments and options) allows you to create custom actions and validators to handle specific requirements: Creating Command-Line Tools with argparse


FunkyShellSearch - User-friendly shell searching FunkyShellSearch - User-friendly shell searching

This is a collection of shell scripts and libraries to be sourced to faciliate shell searching using the well known tools like fd, ag, pdfgrep and fzf . The find and grep utilities are integrated into fzf offering improved preview capabilities and direct actions to specific file types on selection, all configurable through a configuration file:

https://github.com/5n00py/fss

Preview:

https://preview.redd.it/80r7nobzv15c1.jpg

automate deployment of charts using jenkins , ansible and shell automate deployment of charts using jenkins , ansible and shell

Basically I will two jenkins file : jenkinsfile-docker-image-builder and jenkinsfile-action-helmfile

jenkinsfile-docker-image-builder --- build and tag images , update and push charts

Clean the docker from the previous build

Clone the repo

Build tag and save the image in tar format in jenkins artifactory and import in k3s

Update the helm charts with updated image tags and push the helm file to chart repository

jenkinsfile-action-helmfile -- deploy

script Run the script will do installations and configurations on fresh vm like docker , k3s , helm , helmfile -- add the access to the chart repository

Clone helm repo

Login into the target VM (credentilas from the docker build step from jenkinsfile-docker-image-builder pipeline)

Helm deploy charts (install /upgrade as required)

what are better ways to implement the above ?

How can we update the helm charts(values.yaml and chart.yaml) with updated image or image tags and push the helm file to chart repository?

can we do that using ansible ?

How can we include condition weather to install or upgrade the charts ?

Also want to include

Vault -- secret management

Ingress changing traffic rules to correct pod , having only ip address to handle the traffic

Monitoring - metric server fluentd and prometheus