Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 24, 2020 06:12 am GMT

10 tiny helper scripts for devs!

Notes

  • This is a collection of tiny scripts that you can execute through the terminal.
  • These are designed for Ubuntu (with zsh), but may work on other unixy systems
  • Some are stolen scripts, other's are original!
  • Scripts are in various languages e.g; #!/usr/bin/env ruby
  • These are part of a dotfiles collection:

10 tiny helper scripts

(1) git-undo

#!/bin/sh# Undo your last commit  (in current folder), but don't throw away your changesgit reset --soft HEAD^

(2) gclonecd https://github.com/reactjs/react-modal

#!/bin/zsh# Clones git repo and cd's into itgclonecd() {  git_dir="$(basename "$1" .git)"  git_dir_resolved=${2:-$git_dir}  git clone "$@" && cd "$git_dir_resolved";}

(3) killport 3000

#!/bin/zsh# Kills a process running on a specified tcp portkillport() {  echo "Killing process on port: $1"  fuser -n tcp -k $1;}

(4) mvp ./this-dir ./some/other/new/dir

#!/bin/zsh# Move and make parentsfunction mvp () {    source="$1"    target="$2"    target_dir="$(dirname "$target")"    mkdir --parents $target_dir; mv $source $target}

(5) dos2unixd ./dir

#!/bin/zsh# Dos2unix a whole directory (crlf to lf)dos2unixd() {  find $1 -type f -print0 | xargs -0 dos2unix}

(6) docker-kill-all

# Kills all docker containers runningalias docker-kill-all='docker kill `docker ps -aq`'

(7) docker-rm-all

# Deletes all docker containersalias docker-rm-all='docker rm `docker ps -aq`'

(8) git-delete-local-merged

#!/bin/bash## Delete all local branches that have been merged into HEAD. Stolen from# our favorite @tekkub:##   https://plus.google.com/115587336092124934674/posts/dXsagsvLakJbranches=`git branch --merged master | grep -v '\*\|master\|unstable\|develop'`[ -z "$branches" ] && printf '\nNo merged branches to delete...\n' && exit;command="git branch -d $branches"echo ''printf '%s\n' "$branches"echo ''printf 'Delete merged branches locally? Press [Enter] to continue...'read _echo ''echo 'Safely deleting merged local branches...'echo 'Running command: '$command`$command`

(9) git-delete-remote-merged

#!/bin/bashremote='origin'echo "Will delete the following branches from [$remote]:"branches=`git branch -r --merged master | grep -v '\*\|master\|unstable\|develop'`[ -z "$branches" ] && printf '\nNo merged branches to delete...\n' && exit;echo ''printf '%s\n' "$branches"echo ''printf 'Delete merged remote branches from '$remote'? Press [Enter] to continue'read _echo ''echo 'Safely deleting merged remote branches...'echo $branches | sed -e "s:$remote/::g" | xargs -t git push $remote -d

(10) github-open

#!/usr/bin/env ruby# Opens the current github repository in the default browserremotes = `git remote`hasNoRemotes = remotes.size < 2if hasNoRemotes then   returnendrepolink = `git remote get-url origin`if repolink.include?("[email protected]:") then   # Converts from ssh format to https format if necessary  # [email protected]:benwinding/dotfiles  # https://github.com/benwinding/dotfiles  repolink = repolink.gsub("[email protected]:", "https://github.com/")end`xdg-open #{repolink}`

I highly recommend anyone who isn't familiar with shell scripting to checkout holman's dotfiles which is targetted towards make users. Or my own fork ben's dotfiles which is targetted towards ubuntu users.

When you begin writing and maintaining your own little library of scripts and snippets, you'll be amazed at what you can automate and accomplish.


Original Link: https://dev.to/benwinding/10-tiny-helper-scripts-for-devs-knb

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To