Difference between revisions of "BASH Shortcuts"

From PrattWiki
Jump to navigation Jump to search
(EGR 103 Lab Startup)
 
(4 intermediate revisions by the same user not shown)
Line 7: Line 7:
  
 
== Required .bash_profile File ==
 
== Required .bash_profile File ==
If you are a bash shell user, you will also need to have a <code>.bash_profile</code> in your CIFS home directory (the ~ directory) for the shortcuts to work.  The contents of the profile should be:
+
If you are a bash shell user, you will also need to have a <code>.bash_profile</code> in your CIFS home directory (the ~ directory) for the shortcuts to work.  Use <code>emacs</code> to edit the file with the command:
<source lang="bash">
+
emacs ~/.bash_profile &
 +
 
 +
The contents of the profile should be as given below; best bet is to select the text from the browser, middle click in the emacs window to paste, then save the file.:
 +
<syntaxhighlight lang="bash">
 
# .bash_profile
 
# .bash_profile
  
Line 20: Line 23:
  
 
export PATH
 
export PATH
</source>  
+
</syntaxhighlight >  
  
 
== Main Shortcuts ==
 
== Main Shortcuts ==
 +
These shourtcuts should go in a <code>~/.bashrc</code> file.  You will want to copy them from the browser and middle click them in an emacs window you started with:
 +
emacs ~/.bashrc &
  
 
=== EGR 103 Lab Startup ===
 
=== EGR 103 Lab Startup ===
 
You can create a script to automate the process of getting the tar file, expanding it, and making a local copy.  This command should only be used once you have created the appropriate <code>labN</code> folder in your <code>EGR103</code> folder and should only be used if you have changed into that folder!  Type <code>pwd</code> first to make sure you are in the right place!  You can add the following to your <code>.bashrc</code> file:
 
You can create a script to automate the process of getting the tar file, expanding it, and making a local copy.  This command should only be used once you have created the appropriate <code>labN</code> folder in your <code>EGR103</code> folder and should only be used if you have changed into that folder!  Type <code>pwd</code> first to make sure you are in the right place!  You can add the following to your <code>.bashrc</code> file:
<source lang=bash>
+
<syntaxhighlight lang=bash>
 
get103(){
 
get103(){
 
LabNum=$1;
 
LabNum=$1;
wget people.duke.edu/~mrg/EGR103public/Lab${LabNum}Files.tar
+
wget people.duke.edu/~mrg/EGR103/Lab${LabNum}Files.tar
 
tar -kxvf Lab${LabNum}Files.tar
 
tar -kxvf Lab${LabNum}Files.tar
cp -i Lab${LabNum}Sample_S19.tex lab${LabNum}.tex
+
cp -i Lab${LabNum}Sample_S20.tex lab${LabNum}.tex
 
}
 
}
</source>
+
</syntaxhighlight >
and then if you log out and log back in (or type <code>source ~/.bashrc</code>, from that point forward, '''once you are in the correct directory</code>, you can type the command
+
and then if you log out and log back in (or type <code>source ~/.bashrc</code>, from that point forward, '''once you are in the correct directory''', you can type the command
<source lang=bash>
+
<syntaxhighlight lang=bash>
 
get103 N
 
get103 N
</source>
+
</syntaxhighlight >
 
where N is the appropriate lab number and this will get the tar file from Dr. G's web space, expand it, and make a local copy of the lab skeleton in <code>labN.tex</code>.
 
where N is the appropriate lab number and this will get the tar file from Dr. G's web space, expand it, and make a local copy of the lab skeleton in <code>labN.tex</code>.
  
 
=== <code>latex</code> and <code>dvipdf</code> in One Command ===
 
=== <code>latex</code> and <code>dvipdf</code> in One Command ===
 
Now that you need to run both <code>latex</code> and <code>dvipdf</code> to get a PDF file for [[evince]] to look at, you may want to have a shorter way than having to type
 
Now that you need to run both <code>latex</code> and <code>dvipdf</code> to get a PDF file for [[evince]] to look at, you may want to have a shorter way than having to type
<source lang="bash">
+
<syntaxhighlight lang="bash">
 
latex FILE.tex
 
latex FILE.tex
 
dvipdf FILE.dvi
 
dvipdf FILE.dvi
</source>
+
</syntaxhighlight >
 
every time.  To make a /bin/bash shortcut for that, add the following to your <code>.bashrc</code> file:
 
every time.  To make a /bin/bash shortcut for that, add the following to your <code>.bashrc</code> file:
<source lang="bash">
+
<syntaxhighlight lang="bash">
ltx() {
 
MyFile=$1
 
MyFile=${MyFile%%.*}
 
latex $MyFile.tex
 
dvipdf $MyFile.dvi
 
}
 
</source>
 
Note that to use it, you do not need to include the ".tex" at the end of your file name, but you can.  The script will automatically take the extension off whatever you gave as an input.
 
 
 
If you want a version that does some basic error-checking, use this one:
 
<source lang="bash">
 
 
ltx() {
 
ltx() {
 
MyFile=$1;
 
MyFile=$1;
Line 71: Line 65:
 
fi
 
fi
 
}
 
}
</source>
+
</syntaxhighlight >
 +
Note that to use it, you do not need to include the ".tex" at the end of your file name, but you can.  The script will automatically take the extension off whatever you gave as an input.
 +
 
 
From that point on, once the <code>.bashrc</code> runs to start your session, you can simply type
 
From that point on, once the <code>.bashrc</code> runs to start your session, you can simply type
 
  ltx FILE
 
  ltx FILE
Line 78: Line 74:
 
and it will run
 
and it will run
 
  latex FILE.tex
 
  latex FILE.tex
  dvidf FILE.dvi
+
  dvipdf FILE.dvi
  
 
<!--
 
<!--
 
=== Add, Commit, and Push to Git All In One! ===
 
=== Add, Commit, and Push to Git All In One! ===
 
If you want a short command that you can use to change to your EGR103 folder, add files to a repository, commit them all, and push them, here's a shortcut for that:
 
If you want a short command that you can use to change to your EGR103 folder, add files to a repository, commit them all, and push them, here's a shortcut for that:
<source lang="bash">
+
<syntaxhighlight lang="bash">
 
gitpush103() {
 
gitpush103() {
 
cd ~/EGR103
 
cd ~/EGR103
Line 95: Line 91:
 
git push
 
git push
 
}
 
}
</source>
+
</syntaxhighlight >
 
You could include a message when using this.
 
You could include a message when using this.
 
* ''Note'' - until 4:30pm on 9/29, the '$1' piece in the shortcut was $1 instead; this means for that shortcut that the message cannot contain spaces; for instance,
 
* ''Note'' - until 4:30pm on 9/29, the '$1' piece in the shortcut was $1 instead; this means for that shortcut that the message cannot contain spaces; for instance,
<source lang="bash">
+
<syntaxhighlight lang="bash">
 
gitpush103 'My_Message'
 
gitpush103 'My_Message'
</source>
+
</syntaxhighlight >
 
:would work but
 
:would work but
<source lang="bash">
+
<syntaxhighlight lang="bash">
 
gitpush103 'My Message'
 
gitpush103 'My Message'
</source>
+
</syntaxhighlight >
 
:would not.  Putting the single quotes around the '$1' as above fixes that, such that any message between the single quotes will work.
 
:would not.  Putting the single quotes around the '$1' as above fixes that, such that any message between the single quotes will work.
 
* If you do not include a message, the default message is <code>no message</code>
 
* If you do not include a message, the default message is <code>no message</code>
Line 111: Line 107:
 
=== Stayin' Alive ===
 
=== Stayin' Alive ===
 
There is currently a 10-minute inactivity timeout on remote logins.  In order to eliminate this, add the following line to your <code>.bashrc</code> file:
 
There is currently a 10-minute inactivity timeout on remote logins.  In order to eliminate this, add the following line to your <code>.bashrc</code> file:
<source lang="bash">
+
<syntaxhighlight lang="bash">
 
xeyes -geometry 1x1-1-1 &
 
xeyes -geometry 1x1-1-1 &
</source>
+
</syntaxhighlight >
 
This will start the <code>xeyes</code> program off screen and in the background.  With this program running, however, your session will not time out.  If that puts an xeyes window on your screen, try
 
This will start the <code>xeyes</code> program off screen and in the background.  With this program running, however, your session will not time out.  If that puts an xeyes window on your screen, try
 
  xeyes -geometry 1x1-1-100 &
 
  xeyes -geometry 1x1-1-100 &
 
instead.
 
instead.
 
-->
 
-->

Latest revision as of 04:08, 5 February 2020

The following is a list of shortcuts Pratt students may want to add to their .bashrc profile. This, first of all, assumes that they are using the bash shell. To check this, type

echo $SHELL 

If the result is

/bin/bash

than this page applies to you; if not, see the TCSH Shortcuts page.


Required .bash_profile File

If you are a bash shell user, you will also need to have a .bash_profile in your CIFS home directory (the ~ directory) for the shortcuts to work. Use emacs to edit the file with the command:

emacs ~/.bash_profile &

The contents of the profile should be as given below; best bet is to select the text from the browser, middle click in the emacs window to paste, then save the file.:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
      . ~/.bashrc 
fi  

# User specific environment and startup programs
PATH=$PATH:$HOME/bin

export PATH

Main Shortcuts

These shourtcuts should go in a ~/.bashrc file. You will want to copy them from the browser and middle click them in an emacs window you started with:

emacs ~/.bashrc &

EGR 103 Lab Startup

You can create a script to automate the process of getting the tar file, expanding it, and making a local copy. This command should only be used once you have created the appropriate labN folder in your EGR103 folder and should only be used if you have changed into that folder! Type pwd first to make sure you are in the right place! You can add the following to your .bashrc file:

get103(){
LabNum=$1;
wget people.duke.edu/~mrg/EGR103/Lab${LabNum}Files.tar
tar -kxvf Lab${LabNum}Files.tar
cp -i Lab${LabNum}Sample_S20.tex lab${LabNum}.tex
}

and then if you log out and log back in (or type source ~/.bashrc, from that point forward, once you are in the correct directory, you can type the command

get103 N

where N is the appropriate lab number and this will get the tar file from Dr. G's web space, expand it, and make a local copy of the lab skeleton in labN.tex.

latex and dvipdf in One Command

Now that you need to run both latex and dvipdf to get a PDF file for evince to look at, you may want to have a shorter way than having to type

latex FILE.tex
dvipdf FILE.dvi

every time. To make a /bin/bash shortcut for that, add the following to your .bashrc file:

ltx() {
MyFile=$1;
MyFile=${MyFile%%.*}
 
if [[ -f $MyFile.tex ]]
then
   latex $MyFile.tex
   dvipdf $MyFile.dvi
else
  echo "*ERROR*: '$MyFile.tex' not found"
fi
}

Note that to use it, you do not need to include the ".tex" at the end of your file name, but you can. The script will automatically take the extension off whatever you gave as an input.

From that point on, once the .bashrc runs to start your session, you can simply type

ltx FILE

or

ltx FILE.tex

and it will run

latex FILE.tex
dvipdf FILE.dvi