Posted By

willcodeforfood on 12/16/07


Tagged

bashrc


Versions (?)

bash profile 2


 / Published in: Other
 

  1. # mkmv - creates a new directory and moves the file into it, in 1 step
  2. # Usage: mkmv <file> <directory>
  3. mkmv() {
  4. mkdir "$2"
  5. mv "$1" "$2"
  6. }
  7.  
  8. # sanitize - set file/directory owner and permissions to normal values (644/755)
  9. # Usage: sanitize <file>
  10. sanitize() {
  11. chmod -R u=rwX,go=rX "$@"
  12. chown -R ${USER}.users "$@"
  13. }
  14.  
  15. # nh - run command detached from terminal and without output
  16. # Usage: nh <command>
  17. nh() {
  18. nohup "$@" &>/dev/null &
  19. }
  20.  
  21. # run - compile a simple c or cpp file, run the program, afterwards delete it
  22. # Usage: run <file> [params]
  23. run() {
  24. filename="${1%%.*}"
  25. extension="${1##*.}"
  26. file="$1"
  27. shift
  28. params="$@"
  29. command=""
  30.  
  31. if [ $extension = "cc" -o $extension = "cpp" -o $extension = "c++" ]; then
  32. command="g++"
  33. elif [ $extension = "c" ]; then
  34. command="gcc"
  35. else
  36. echo "Invalid file extension!"
  37. return 1
  38. fi
  39.  
  40. $command -Wall -o $filename $file
  41. chmod a+x $filename
  42. ./$filename $params
  43. rm -f $filename 2>/dev/null
  44. }

Report this snippet  

You need to login to post a comment.