Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Auto insert command options

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
User avatar
Soapm
Posts: 602
Joined: 2012-05-22 04:23
Has thanked: 1 time

Auto insert command options

#1 Post by Soapm »

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?

cronoik
Posts: 310
Joined: 2015-05-20 21:17

Re: Auto insert command options

#2 Post by cronoik »

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!

xepan
Posts: 89
Joined: 2018-11-28 06:38

Re: Auto insert command options

#3 Post by xepan »

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.

User avatar
Soapm
Posts: 602
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: Auto insert command options

#4 Post by Soapm »

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: 602
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: Auto insert command options

#5 Post by Soapm »

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

cronoik
Posts: 310
Joined: 2015-05-20 21:17

Re: Auto insert command options

#6 Post by cronoik »

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!

User avatar
Soapm
Posts: 602
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: Auto insert command options

#7 Post by Soapm »

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???

cronoik
Posts: 310
Joined: 2015-05-20 21:17

Re: Auto insert command options

#8 Post by cronoik »

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!

User avatar
Soapm
Posts: 602
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: Auto insert command options

#9 Post by Soapm »

works like a charm, thanks...

pendrachken
Posts: 1394
Joined: 2007-03-04 21:10
Location: U.S.A. - WI.

Re: Auto insert command options

#10 Post by pendrachken »

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

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Auto insert command options

#11 Post by Head_on_a_Stick »

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 :)
deadbang

xepan
Posts: 89
Joined: 2018-11-28 06:38

Re: Auto insert command options

#12 Post by xepan »

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).

User avatar
Soapm
Posts: 602
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: Auto insert command options

#13 Post by Soapm »

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: 602
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: Auto insert command options

#14 Post by Soapm »

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...

pendrachken
Posts: 1394
Joined: 2007-03-04 21:10
Location: U.S.A. - WI.

Re: Auto insert command options

#15 Post by pendrachken »

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

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Auto insert command options

#16 Post by Head_on_a_Stick »

Soapm wrote: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?
Yes, it is possible :)

See https://mywiki.wooledge.org/BashGuide/T ... _.7C.7C.29 & https://mywiki.wooledge.org/BashGuide/T ... _.5B.5B.29
deadbang

xepan
Posts: 89
Joined: 2018-11-28 06:38

Re: Auto insert command options

#17 Post by xepan »

The same guide says:
Aliases are limited in power; the replacement only happens in the first word. To have more flexibility, use a function. Aliases are only useful as simple textual shortcuts.
...
Functions in Bash are somewhat like aliases, but more powerful. Unlike aliases, they can be used in scripts. A function contains shell commands, and acts very much like a small script; they can even take arguments and create local variables.

The bot is slightly more unfriendly in recommending against aliases in favor of functions.

So i tend to agree with pendrachken:
pendrachken wrote: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.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Auto insert command options

#18 Post by Head_on_a_Stick »

xepan wrote:The same guide says:
Aliases are limited in power; the replacement only happens in the first word. To have more flexibility, use a function. Aliases are only useful as simple textual shortcuts.
Yes but all the OP needed was a simple, textual shortcut and unless the user understands what "${@}" means then my alias is easier to interpret, understand and modify than your function.

But yes, I would generally agree that functions are far more flexible and useful than aliases (aliai?).
deadbang

xepan
Posts: 89
Joined: 2018-11-28 06:38

Re: Auto insert command options

#19 Post by xepan »

Just chatting.
In general i was wondering if aliases can do tests/conditionals, they seem to, and then if that would be a stretch or not.
I sure never saw it in aliases, a quick web-search was not successful either, but i wouldn't really know.

Post Reply