.bash_profile command arguments - bash

I was looking for a redhat Tree command workaround and keep finding this specifically
alias lst='ls -R | grep ":$" | sed -e '"'"'s/:$//'"'"' -e '"'"'s/[^-][^\/]*\//--/g'"'"' -e '"'"'s/^/ /'"'"' -e '"'"'s/-/|/'"'"
I'm trying to add files to the output tree and I have no idea what any of this is saying, could someone tell me what this command is saying and how to add to it?

Related

git keyword substitution under windows using gnutools (gnuwin32)

I just converted my SVN repository to git. For the management I use keyword-substitution.
Excerpt from the git config
smudge = "set author=`git log --pretty=format:%ae -1`; SET last_date=`git log --pretty=format:\"%ai\" -1`; SET version=`echo $lastdate | cut -d \" \" -f 1-2 | sed -e \"s/[ -:]/./g\"`; sed -e \"s/[$]Revision[$]/\\$Revision: $last_date \$/\" -e \"s/[$]Date[$]/\\$Date: $last_date \$/\" -e \"s/[$]Author[$]/\\$Author: $author \\$/\" "
clean = sed -r -e 's/([$]Revision|Date|Author)(:[^$]+ [$])/\\1$/'
Source: https://github.com/np-trivial/git-keyword-substitution
This solution should in principle also run under Windows, since I also use gnuwin32. Tools are accessible in the system environment variable.
Unfortunately I always get an error message. As far as I could isolate it is because of the above code.
I just have no idea what the problem is.
You do not need gnuwin32.
Content filter driver would work from a regular CMD session, and would be executed with the git bash included with Git for Windows.
That means your smudge/clean scripts should be in bash.
set xx= is a BAT assignmemnt. xx=... is a bash assignment.
Try:
smudge = "author=$(git log --pretty=format:%ae -1); last_date=$(git log --pretty=format:\"%ai\" -1); version=$(echo $lastdate | cut -d \" \" -f 1-2 | sed -e \"s/[ -:]/./g\"); sed -e \"s/[$]Revision[$]/\\$Revision: $last_date \$/\" -e \"s/[$]Date[$]/\\$Date: $last_date \$/\" -e \"s/[$]Author[$]/\\$Author: $author \\$/\" "
clean = sed -r -e 's/([$]Revision|Date|Author)(:[^$]+ [$])/\\1$/'
In other words, remove the set.
However, the OP ozz confirms in the comments that SmartGit does not support content filter driver.
A simple git checkout or git switch does triggers it (successfully) in command-line though.

sed: can't read ../../build.gradle: No such file or directory

I am new to git and github. I am working on a project where I need to commit my changes to github repository in a specific branch.
But I am getting the error
$ git commit
3.5.0.1
s/3.5.0.1/3.5.1.1/g
sed: can't read ../../build.gradle: No such file or directory
I have also attached the pre-commit file code here.
#!/bin/sh
## finding the exact line in the gradle file
#ORIGINAL_STRING=$(cat ../../build.gradle | grep -E '\d\.\d\.\d\.\d')
## extracting the exact parts but with " around
#TEMP_STRING=$(echo $ORIGINAL_STRING | grep -Eo '"(.*)"')
## the exact numbering scheme
#FINAL_VERSION=$(echo $TEMP_STRING | sed 's/"//g') # 3.5.0.1
#Extract APK version
v=$(cat build.gradle | grep rtVersionName | awk '{print $1}')
FINAL_VERSION=$(echo ${v} | cut -d"\"" -f2)
echo ${FINAL_VERSION}
major=0
minor=0
build=0
assets=0
regex="([0-9]+).([0-9]+).([0-9]+).([0-9]+)"
if [[ $FINAL_VERSION =~ $regex ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
build="${BASH_REMATCH[3]}"
assets="${BASH_REMATCH[4]}"
fi
# increment the build number
build=$(echo $build + 1 | bc)
NEW_VERSION="${major}.${minor}.${build}.${assets}"
SED_ARGUMENT=$(echo "s/${FINAL_VERSION}/${NEW_VERSION}/g")
echo $SED_ARGUMENT
sed -i -e `printf $SED_ARGUMENT` ../../build.gradle
The error comes in the last line of this file basically. I am using windows.
Things I tried:
sed -i -e `printf $SED_ARGUMENT` ../../build.gradle
sed -i ' ' -e `printf $SED_ARGUMENT` ../../build.gradle
I am unable to understand where am I actually doing wrong. Kindly help me out.
sed: can't read ../../build.gradle: No such file or directory
This one is rather simple. Your build.gradle file is not at ../../build.gradle.
The solution is to determine actual path to the build.gradle file relative to the script, and change the path in the script.
To debug this, do echo Current Directory: $PWD in the script to see what the actual working directory is, then you should be able to determine the correct path to use.

How to set ranger as default file manager

Related: Here, Here, Here, & Here.
I want to be able to use gui applications with ranger, e.g., I want to click a desktop folder icon & have it open in ranger.
Steps I take & errors that follow:
Set /home/ertecturing/.scripts/Ranger_Default_File_Manager.sh "%s" as default file manager in xfce settings
Ranger_Default_File_Manager.sh runs
xfce4-terminal -T "Ranger File Manager" -x ranger $#
This commands almost works, but it creates a directory error because directories given by $# always start with only file:/// not file://// like they need to in order to function.
I tried to add the missing 4th slash with this sed command someone shared with me:
OUT=$(sed -e 's/\/\/\//\/\/\/\//g' $1)
xfce4-terminal -T "Ranger File Manager" -x ranger $OUT
I have little idea whether that first line's syntax is correct.
The first line only produces blank output, but if I test a similar command echo $# | sed "s/\/\/\//\/\/\/\//g" >> ~/Desktop/file it always outputs the 4th slash I'm looking for.
Does anyone know a way to solve this issue? Help is highly appreciated.
Changing your OUT variable to the command that you say works may be a better approach.
OUT=$(echo "$#" | sed 's|$|/|g')
Additional Solution for Spaces:
OUT=$(echo "$#" | sed "s:///:////:g" | sed "s/%20/ /g")
xfce4-terminal -T "Ranger File Manager" -x ranger "$OUT"

Why is grep displaying command as part of output?

I have written a bash script that finds any executable files in our scripts directory, then performs a grep on the resulting files to display a description, if it was included in the file.
A "description" is identified in each file as a line beginning with "# DESC:"
For some reason, the script also includes the grep command that is being run (but only once). Does anyone know why this is?
Script and output shown below. Why does the second line in the output happen?
Script
#!/bin/bash
# Find any FILES that are EXECUTABLE in the SCRIPTS
# directory and display any description, if there is one
find /opt/scripts/. -perm -111 -type f -maxdepth 1 | while read line ;
do
file=$(basename "$line")
printf "\033[1m%10s\033[0m : " $file
grep "# DESC:" "$line" | cut -c 9-
done
Output
desc : Displays all the scripts and their descriptions
DESC:" "$line" | cut -c 9-
showhelp : Displays the script help file
test : Script to perform system testing
Reason
Presumably your grepping script is also in /opt/scripts?
So it finds itself, and finds the grep subject '#DESC' and prints that.
You could fix that by adding a # DESC line to the top of your grep script, and just outputting the first result found by each grep using 'grep -m1'
grep -m1 '# DESC' "$line" | cut -c 9-
<humour>Otherwise its just turtles all the way down... ;-) </humour>
Alternative Fix
You could also improve the grep by using a regular expression and anchoring to the beginning of the line:
egrep -m1 '^# DESC' "$line" | cut -c 9-

Using sed to swap Windows location for Mac

I am writing a bash script for an automator service that will take a Windows directory location and change it to Mac and open a finder window. It's working except for when it hits folders with spaces. I have put in to remove them but it won't work on anything with spaces still. I must have made some sort of syntax mistake.
sed -e 's:\\\\fmg_cifs1\\Dept_Shares:/Volumes/Dept_Shares:' -e 's: :\ :g' -e 's:\\:/:g' | pbcopy
TAG=$(pbpaste)
cd $TAG; open .
This is almost certainly all you have to change:
cd "$TAG"
Quoting fixes everything!
Do you need to use pbcopy and pbpaste and a variable?
cd "$(sed -e 's:\\\\fmg_cifs1\\Dept_Shares:/Volumes/Dept_Shares:' -e 's: :\ :g' -e 's:\\:/:g')"
As Jonathan pointed out, some of the sed command is unnecessary. Of course, something needs to be fed to sed. This may be all you need:
cd "$(echo "$dir" | sed -e 's:\\\\fmg_cifs1\\Dept_Shares:/Volumes/Dept_Shares:')"

Resources