Skip to content

Commit

Permalink
weather info script addedl,issue iiitl#2
Browse files Browse the repository at this point in the history
  • Loading branch information
Karanagarwal12 committed Mar 16, 2024
0 parents commit b6983a2
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Foss BashScripting

See [scripts](./scripts) folder for more information.

Whereever there is a work to do, there will be a comment present with word "TODO".

## Running scripts

After cd into this repository
```bash
export PATH="$PATH:$PWD/scripts"

# All scripts are ready to execute by their name
```

## Some external resources

* [Linux Basics & CLI Tutorial](https://www.freecodecamp.org/news/linux-command-line-tutorial)
* [Learn X in Y Minutes - Bash](https://learnxinyminutes.com/docs/bash/)
20 changes: 20 additions & 0 deletions scripts/color
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# TODO (Run this script as): color magenta && echo hello && color reset

color() {
echo -ne "\033[$1;$2m"
}

declare -A color_mapping=(
# TODO: Add more color values
# Refer bash color codes
['magenta']=35
)

if [[ $1 == 'reset' ]]; then
color 0 00
else
color 1 ${color_mapping[$1]}
fi

8 changes: 8 additions & 0 deletions scripts/cpu-temperature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

grep -E 'Tctl|Tdie|Package id' /sys/class/hwmon/hwmon*/temp*_label | head -n1 | cut -d':' -f1 | sed 's/label/input/' | xargs cat

# Following script outputs current cpu die temperature in milidegree-celcius, convert it to celcius and fahrenheit and display as:
#
# Celcius: 42.0 C
# Fahrenheit: 107.6 F
33 changes: 33 additions & 0 deletions scripts/extarrange
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

# Arranges the files by grouping them into folder of their extension name
# TODO: Run this script in your downloads folder

require() {
command -v "$1" 1>/dev/null || { >&2 echo "Error: $1 is not installed";exit 1; }
}

require fd
require egrep

declare -A special_cases=(
['^*.(tar.*|tbz)$']='tar'
# TODO: Add your own pattern here for similar file types appropriately
# Refer https://regex101.com/ & https://github.com/ziishaned/learn-regex/ for explaination and writing patterns
# These (regex) are same as ones used in sed command
)

fd -tf -d1 \
| while read file; do
folder="$PWD/${file##*.}"
for regex in "${!special_cases[@]}"; do
(echo "$file" | egrep -q "$regex") && {
folder="$PWD/${special_cases[$regex]}"
break
}
done

mkdir -p "$folder"
mv "$file" "$folder"
done

4 changes: 4 additions & 0 deletions scripts/gitlines
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

# TODO: Display lines of code by language in a remote git repository
# Refer "cloc" command or similar
28 changes: 28 additions & 0 deletions scripts/music-extract
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# TODO: Make a ffmpeg script which takes all the mp4 files in a folder (recursively) and output them in the same position mp3 file
#
# E.g.:
# Videos
# ├── Clips
# │ ├── clip1.mp4
# │ └── clip2.mp4
# ├── Movies
# │ ├── movie1.mp4
# │ └── movie2.mp4
# └── Songs
# ├── Song1.mp4
# └── Song2.mp4
# music-extract Videos
#
# The above folder will create another folder with the position of file with just there audio
# Music
# ├── Clips
# │ ├── clip1.mp3
# │ └── clip2.mp3
# ├── Movies
# │ ├── movie1.mp3
# │ └── movie2.mp3
# └── Songs
# ├── Song1.mp3
# └── Song2.mp3
5 changes: 5 additions & 0 deletions scripts/password-generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

# Issue: Implement Password Generation Functions
# Description:
# Create a function that generates passwords, The password should consist of uppercase letters, lowercase letters, numbers, and special characters. The function should take in a single argument, which is the length of the password to generate. The function should return the generated password.
9 changes: 9 additions & 0 deletions scripts/perms
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

# TODO: Make it print out permissions of the given files in octal format
#
# E.g.:
# $ perms weather ../README.md
# 775 weather
# 664 ../README.md

4 changes: 4 additions & 0 deletions scripts/rm-bins
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

# Remove all the binary files (usually made after gcc) present inside current directory
# Refer "man find" for more information, you can also use modern tool like fd instead of find
4 changes: 4 additions & 0 deletions scripts/rm-gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

# Removes all files written in .gitignore of any git repository (multiple) present inside current directory
# To find list of all git repos inside current directory you can use: "find . -name .git -type d -prune"
8 changes: 8 additions & 0 deletions scripts/weather
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

# TODO: Display weather of IIIT, Lucknow
# For more information see: https://wttr.in/:help

echo "Weather at your location--"
weather=$(curl -s wttr.in)
echo "$weather" | tail -n +2 | head -n -1
4 changes: 4 additions & 0 deletions scripts/wifi-ssid
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

# Extract the wifi username (SSID)
# Refer: "iw dev wlan0 link" command output for this
8 changes: 8 additions & 0 deletions scripts/youtube-time
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

# TODO: Make a script to download youtube video from given timeframes
#
# E.g.: youtube-time 2:00 4:00 tutorial.mkv "https://www.youtube.com/watch?v=SPwyp2NG-bE"
# The above command should create a output file which contains the video from 2 min to 4 min.
#
# Refer: youtube-dl and ffmpeg commands for this

0 comments on commit b6983a2

Please sign in to comment.