Auto insert command options

New to Debian (Or Linux in general)? Ask your questions here!

Auto insert command options

Postby Soapm » 2018-12-04 09:35

I'm checking the normalization on a lot of music files using fffmpeg with these cli options;

Code: Select all
ffmpeg -i file.mp3 -af "volumedetect" -vn -sn -dn -f null /dev/null


Is there a simple way to put the;

Code: Select all
-af "volumedetect" -vn -sn -dn -f null /dev/null


on the command line so I don't have to look it up and type it manually each time?
User avatar
Soapm
 
Posts: 541
Joined: 2012-05-22 04:23

Re: Auto insert command options

Postby cronoik » 2018-12-04 10:01

Add this line (a function) tor your .bashrc and save it:
Code: Select all
ownecho () { echo "$@" blabla  ; }

You can activate your new .bashrc in the current terminal now with:
Code: Select all
source .bashrc

(or you can just start a new session):
After the activation you can type the following:
Code: Select all
ownecho hello
Last edited by cronoik on 2018-12-04 20:31, edited 3 times in total.
Have a nice day!
cronoik
 
Posts: 286
Joined: 2015-05-20 21:17

Re: Auto insert command options

Postby xepan » 2018-12-04 15:44

If you edit /etc/inputrc and change to this:
Code: Select all
# mappings for "page up" and "page down" to step to the beginning/end
# of the history
# "\e[5~": beginning-of-history
# "\e[6~": end-of-history

# alternate mappings for "page up" and "page down" to search the history
"\e[5~": history-search-backward
"\e[6~": history-search-forward

then you can type the beginning of the command, say "ffm", then hit page up, and it will complete whatever in your history started with "ffm" (hit page up as often as it takes, or make the beginning more unique).
iirc debian's inputrc has that entry, but commented.
In this case you probably want a function as proposed by cronoik though.
xepan
 
Posts: 11
Joined: 2018-11-28 06:38

Re: Auto insert command options

Postby Soapm » 2018-12-04 19:40

cronoik wrote:Just add a function to your .bashrc:

Code: Select all
ownecho () { echo "$@" blabla  ; }

Code: Select all
source .bashrc

Code: Select all
ownecho hello


You seem a bit over my head, I use joe as my text editor and am familiar with editing my bash using;

Code: Select all
joe ~/.bashrc


However, I can't visualize the command you're proposing entering into the file to make it output the options part of the command nor do I know what to type on the cli to activate it..

I am familiar with aliases like the one I use to rip dvd's;

Code: Select all
alias rip='time ripdvd.sh &'


I just move to the directory and type "rip" and there it goes. Are you suggesting something similar to this?
User avatar
Soapm
 
Posts: 541
Joined: 2012-05-22 04:23

Re: Auto insert command options

Postby Soapm » 2018-12-04 19:53

xepan wrote:If you edit /etc/inputrc and change to this:
Code: Select all
# mappings for "page up" and "page down" to step to the beginning/end
# of the history
# "\e[5~": beginning-of-history
# "\e[6~": end-of-history

# alternate mappings for "page up" and "page down" to search the history
"\e[5~": history-search-backward
"\e[6~": history-search-forward

then you can type the beginning of the command, say "ffm", then hit page up, and it will complete whatever in your history started with "ffm" (hit page up as often as it takes, or make the beginning more unique).
iirc debian's inputrc has that entry, but commented.
In this case you probably want a function as proposed by cronoik though.


My command line already remembers commands using page up and down, I'm just looking to have it enter the last portion of the command. Just the part with the options since I have to manually enter ffmpeg -i filename.mp3. I just want it to add this to the end;

Code: Select all
-af "volumedetect" -vn -sn -dn -f null /dev/null
User avatar
Soapm
 
Posts: 541
Joined: 2012-05-22 04:23

Re: Auto insert command options

Postby cronoik » 2018-12-04 20:29

Soapm wrote:You seem a bit over my head,...

I'm sorry, English is not my mother tongue and therefore I tend keep my answer's unintentionally short. I have edited my post above to make it more clear.
Have a nice day!
cronoik
 
Posts: 286
Joined: 2015-05-20 21:17

Re: Auto insert command options

Postby Soapm » 2018-12-04 20:43

cronoik wrote:
Soapm wrote:You seem a bit over my head,...

I'm sorry, English is not my mother tongue and therefore I tend keep my answer's unintentionally short. I have edited my post above to make it more clear.


You're fine and appreciated, I got it to work but im not sure how it helps me.

If I put ownecho in the options part of the command it says its not a legitimate option???
User avatar
Soapm
 
Posts: 541
Joined: 2012-05-22 04:23

Re: Auto insert command options

Postby cronoik » 2018-12-04 21:48

Another misunderstanding, sorry. Ownecho was just an example to show you how a function with parameter can be defined. So for your ffmpeg command you can define something like this in your .bashrc:

Code: Select all
ownffmpeg () { ffmpeg -i "$@" -af "volumedetect" -vn -sn -dn -f null /dev/null  ; }

After sourcing the .bashrc:
Code: Select all
source .bashrc

You can type the following:
Code: Select all
ownffmpeg file.mp3

which will execute the code in the curly brackets and this is what you wanted, right?
Have a nice day!
cronoik
 
Posts: 286
Joined: 2015-05-20 21:17

Re: Auto insert command options

Postby Soapm » 2018-12-04 22:58

works like a charm, thanks...
User avatar
Soapm
 
Posts: 541
Joined: 2012-05-22 04:23

Re: Auto insert command options

Postby pendrachken » 2018-12-05 02:20

Soapm wrote:
cronoik wrote:Just add a function to your .bashrc:

Code: Select all
ownecho () { echo "$@" blabla  ; }

Code: Select all
source .bashrc

Code: Select all
ownecho hello


You seem a bit over my head, I use joe as my text editor and am familiar with editing my bash using;

Code: Select all
joe ~/.bashrc


However, I can't visualize the command you're proposing entering into the file to make it output the options part of the command nor do I know what to type on the cli to activate it..

I am familiar with aliases like the one I use to rip dvd's;

Code: Select all
alias rip='time ripdvd.sh &'


I just move to the directory and type "rip" and there it goes. Are you suggesting something similar to this?



So why not make an alias, something like checklevels with the ffmpeg options you want then? Or take the two minutes to learn the BASH you need to write a script that you can place in your $PATH so you just

Code: Select all
myscript mymp3.mp3


So it's portable between computers. You just have to copy the script and make sure ffmpeg is installed on the new PC.
fortune -o
Your love life will be... interesting.
:twisted: How did it know?

The U.S. uses the metric system too, we have tenths, hundredths and thousandths of inches :-P
pendrachken
 
Posts: 1331
Joined: 2007-03-04 21:10
Location: U.S.A. - WI.

Re: Auto insert command options

Postby Head_on_a_Stick » 2018-12-05 06:07

This would also work as an alias:
Code: Select all
# ~/.bashrc
alias voldt='ffmpeg -af "volumedetect" -vn -sn -dn -f null /dev/null -i'

Then use
Code: Select all
voldt $name_of_mp3

^ Replace $name_of_mp3 with the name of the mp3 track :)
dbruce wrote:Ubuntu forums try to be like a coffee shop in Seattle. Debian forums strive for the charm and ambience of a skinhead bar in Bacau. We intend to keep it that way.
User avatar
Head_on_a_Stick
 
Posts: 8315
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Auto insert command options

Postby xepan » 2018-12-05 07:26

Soapm wrote:My command line already remembers commands using page up and down, I'm just looking to have it enter the last portion of the command. Just the part with the options since I have to manually enter ffmpeg -i filename.mp3. I just want it to add this to the end;

Code: Select all
-af "volumedetect" -vn -sn -dn -f null /dev/null

Yup, i was aware that in your case it is not that helpful. Use autocomplete command from history via page-up, but then you have to edit that command.
That's why i said the proposed usage of a function is the better solution for your problem (#bash proposes to always use functions instead of aliases, but i don't really understand the reasoning).
I only mentioned it because i thought you wouldn't know it at all . And it saves a lot of typing in the long run. I hardly type more than the beginning of my usual commands and oneliners.

If you could put "-i filename" at the end", then it would work comfortable too, of course ("ffm", page-up, remove filename and insert other filename, hit enter).
xepan
 
Posts: 11
Joined: 2018-11-28 06:38

Re: Auto insert command options

Postby Soapm » 2018-12-05 15:55

xepan wrote:
Soapm wrote:My command line already remembers commands using page up and down, I'm just looking to have it enter the last portion of the command. Just the part with the options since I have to manually enter ffmpeg -i filename.mp3. I just want it to add this to the end;

Code: Select all
-af "volumedetect" -vn -sn -dn -f null /dev/null

Yup, i was aware that in your case it is not that helpful. Use autocomplete command from history via page-up, but then you have to edit that command.
That's why i said the proposed usage of a function is the better solution for your problem (#bash proposes to always use functions instead of aliases, but i don't really understand the reasoning).
I only mentioned it because i thought you wouldn't know it at all . And it saves a lot of typing in the long run. I hardly type more than the beginning of my usual commands and oneliners.

If you could put "-i filename" at the end", then it would work comfortable too, of course ("ffm", page-up, remove filename and insert other filename, hit enter).


Gotcha, I guess I was viewing the steak through the tail end of the cow... thanks.
User avatar
Soapm
 
Posts: 541
Joined: 2012-05-22 04:23

Re: Auto insert command options

Postby Soapm » 2018-12-05 16:03

Head_on_a_Stick wrote:This would also work as an alias:
Code: Select all
# ~/.bashrc
alias voldt='ffmpeg -af "volumedetect" -vn -sn -dn -f null /dev/null -i'

Then use
Code: Select all
voldt $name_of_mp3

^ Replace $name_of_mp3 with the name of the mp3 track :)


Thanks for all the tips guys, it's been so long since I set up those aliases that I just forgot how to apply them in a different scenario. This is why I got off google and came here, I see my options are about unlimited with scripts, aliases etc...

Is it possible to put an "IF" statement in a, alias or command line, like IF the file needs normalizing then run the second command to normalize the file up to 0db?

Just figured I'd ask since we're on the subject...
User avatar
Soapm
 
Posts: 541
Joined: 2012-05-22 04:23

Re: Auto insert command options

Postby pendrachken » 2018-12-06 02:03

You should be able to.

This is why I recommended a script though, it's easier to do what you want and have comments interspersed throughout to remind you of what tit is doing. That can you can just plop the script into the $PATH on any machine with BASH and ffmpeg and use it without having to either replace the stock .bashrc or cut / paste lines into the stock one to get the functionality back.
fortune -o
Your love life will be... interesting.
:twisted: How did it know?

The U.S. uses the metric system too, we have tenths, hundredths and thousandths of inches :-P
pendrachken
 
Posts: 1331
Joined: 2007-03-04 21:10
Location: U.S.A. - WI.

Next

Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 6 guests

fashionable