Show HN: Made a quick filesharing bash script inspired by another Show HN post

https://news.ycombinator.com/item?id=33110574
by sanroot99 • 4 years ago
2 2 4 years ago

I got inspiration from this post https://news.ycombinator.com/item?id=33094627

Here is the script

#!/bin/bash qrcode() {

  qrcode-terminal "http://"$(ip addr show wlp3s0 |grep -Eo $ipregex |head -n1 )":9000/"
  cd ~/.webshare && python3 -m http.server 9000 
} share()

{ if [[ "$1" = "f" ]] then echo "success $1"

  [[ ! -d ~/.webshare   ]] && mkdir -p ~/.webshare 
  #cp  -r --reflink "$2" ~/.webshare/ 
  path="$(realpath "$2")"
  ln -s "$path" "/home/sanbotbtrfs/.webshare/"
  qrcode
elif [[ "$1" = "s" ]] then path="$( find "$2" |fzf )" path="$(realpath "$path")" ln -s "$path" "/home/sanbotbtrfs/.webshare/" qrcode else error fi }

cleanup() { echo 'cleanup operation ' rm -vrf ~/.webshare/* } error() { echo 'usage share [s/f] <filename/dir> ; s is for fuzzy search and f is regular '

} trap cleanup 1 2 3 6 14 15 ; [[ $# -eq 2 ]] && share "$1" "$2" || error

Related Stories

Loading related stories...

Source preview

news.ycombinator.com