Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. % !TeX encoding = UTF-8
  2. \ProvidesPackage{bashline}[2016/10/24 v. 0.1]
  3.  
  4. \makeatletter
  5. \newcommand{\bashline@file@name}[1]{%
  6. /tmp/${USER}-${HOSTNAME}-\jobname-#1.tex%
  7. }
  8. \newread\bashline@file
  9. \newcommand{\bashline@command@one}[2][tmp]{%
  10. \immediate\write18{#2 > \bashline@file@name{#1}}
  11. \openin\bashline@file=\bashline@file@name{#1}
  12. % The group localizes the change to \endlinechar
  13. \bgroup
  14. \endlinechar=-1
  15. \read\bashline@file to \localline
  16. % Since everything in the group is local,
  17. % we have to explicitly make the assignment global
  18. \global\let\bashline@result\localline
  19. \egroup
  20. \closein\bashline@file
  21. % Clean up after ourselves
  22. \immediate\write18{rm \bashline@file@name{#1}}
  23. \bashline@result
  24. }
  25. \newcommand{\bashline@command@many}[2][tmp]{%
  26. \immediate\write18{#2 > \bashline@file@name{#1}}
  27. \openin\bashline@file=\bashline@file@name{#1}
  28. % The group localizes the change to \endlinechar
  29. \newcount\linecnt
  30. \bgroup
  31. \endlinechar=-1
  32. \loop\unless\ifeof\bashline@file
  33. \read\bashline@file to \localline%
  34. \localline
  35. \newline
  36. \repeat
  37. \egroup
  38. \closein\bashline@file
  39. % Clean up after ourselves
  40. \immediate\write18{rm \bashline@file@name{#1}}
  41. }
  42. \newcommand{\bashline}[2][tmp]{%
  43. \bashline@command@one[#1]{#2}%
  44. }
  45. \newcommand{\bashlines}[2][tmp]{%
  46. \bashline@command@many[#1]{#2}%
  47. }
  48. \makeatother
  49.  
  50. \newcommand{\urandomstring}[1]{%
  51. \bashline{cat /dev/urandom | tr -dc "A-Za-z0-9" | fold -c#1 | head -1}%
  52. }
  53.  
  54. \newcommand{\bashdate}{%
  55. \bashline{date --iso-8601}%
  56. }
  57.  
  58. \newcommand{\bashdatetime}{%
  59. \bashline{date --iso-8601=seconds}%
  60. }
  61.  
  62. \newcommand{\commit}{%
  63. \bashline{git describe --dirty }%
  64. }
  65.  
  66. \newcommand{\commitlog}{%
  67. \bashline{git log -1 --oneline}%
  68. }
  69.  
  70. \newcommand{\branch}{%
  71. \bashline{git describe --all}%
  72. }
  73.  
  74. \endinput
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement