diff --git a/jwmappbuilder.v b/jwmappbuilder.v index 8475ce1..cfd9e9b 100644 --- a/jwmappbuilder.v +++ b/jwmappbuilder.v @@ -2,16 +2,19 @@ import os fn main() { mut args := []bool{len: 3} + mut complete := false for mut arg in args { arg = false } for arg in os.args { + /* match arg { + "-i", "--icons" { args[0] = true } "-t", "--tooltip" { args[1] = true } "-a", "--all" { args[2] = true } "-h", "--help" { - println("\nUsage:\n ${os.args[0]} [-h] [-t] [-i] [-a]\n\nGenerates Applications menu for Joe's Window Manager.\n\nUsage in .jwmrc:\n\n\texec: ${os.args[0]} \n\nOptions:\n -h, --help\tShow this text.\n -i, --icons\tAlso generate icons.\n -t, --tooltip\tAlso generate tooltips.\n -a, --all\tDo not generate categories: list all applications.\n\nv1.0") + println("\nUsage:\n ${os.args[0]} [-h] [-t] [-i] [-a]\n\nGenerates Applications menu for Joe's Window Manager.\n\nUsage in .jwmrc:\n\n\texec: ${os.args[0]} \n\nOptions:\n -h, --help\tShow this text.\n -i, --icons\tAlso generate icons.\n -t, --tooltip\tAlso generate tooltips.\n -a, --all\tDo not generate categories: list all applications.\n\nv1.1") exit(0) } else { if arg == os.args[0] {} else { @@ -19,8 +22,27 @@ fn main() { exit(1) } } + + + + }*/ + if !(arg == os.args[0]) { + if arg.contains('h') && arg.contains('-') { + println("\nUsage:\n ${os.args[0]} [-h] [-tia]\n\nGenerates Applications menu for Joe's Window Manager.\n\nUsage in .jwmrc:\n\n\texec: ${os.args[0]} \n\nOptions:\n -h, --help\tShow this text.\n -i, --icons\tAlso generate icons.\n -t, --tooltip\tAlso generate tooltips.\n -a, --all\tDo not generate categories: list all applications.\n\nv1.1") + exit(0) + } + complete = false + if arg.contains('i') && arg.contains('-') { args[0] = true; complete = true } + if arg.contains('t') && arg.contains('-') { args[1] = true; complete = true } + if arg.contains('a') && arg.contains('-') { args[2] = true; complete = true } + if !complete { + println("Unknown argument: ${arg}") + exit(1) + } } + } + if !args[2] { categorymode(args) } else { @@ -41,6 +63,17 @@ fn allmode(args []bool){ println('') } +fn buildcategory(args []bool, folder string, item string, catname string, mut linkslist []string) { + println('') + for mut elem in linkslist { + if !(elem.contains('/IM/')) && checktargetcategory(elem, item) { + println(buildprogram('${folder}${elem}', args)) + elem = '/IM/' + } + } + println('') +} + fn categorymode(args []bool) { mut linkslist := os.ls('/usr/share/applications/') or { panic(err) } println('\n\n') @@ -49,54 +82,15 @@ fn categorymode(args []bool) { if !(item.contains('.desktop')) || item.contains('krita_') { item = '/IM/' } } - for mut item in linkslist { - if !(item.contains('/IM/')) && checktargetcategory(item, "Utility") { - println(buildprogram('/usr/share/applications/${item}', args)) - item = '/IM/' - } - } - println('\n') - for mut item in linkslist { - if !(item.contains('/IM/')) && checktargetcategory(item, "Office") { - println(buildprogram('/usr/share/applications/${item}', args)) - item = '/IM/' - } - } - println('\n') - for mut item in linkslist { - if !(item.contains('/IM/')) && checktargetcategory(item, "Game") { - println(buildprogram('/usr/share/applications/${item}', args)) - item = '/IM/' - } - } - println('\n') - for mut item in linkslist { - if !(item.contains('/IM/')) && checktargetcategory(item, "Graphics") { - println(buildprogram('/usr/share/applications/${item}', args)) - item = '/IM/' - } - } - println('\n') - for mut item in linkslist { - if !(item.contains('/IM/')) && checktargetcategory(item, "Network") { - println(buildprogram('/usr/share/applications/${item}', args)) - item = '/IM/' - } - } - println('\n') - for mut item in linkslist { - if !(item.contains('/IM/')) && checktargetcategory(item, "System") { - println(buildprogram('/usr/share/applications/${item}', args)) - item = '/IM/' - } - } - println('\n') - for mut item in linkslist { - if !(item.contains('/IM/')) { - println(buildprogram('/usr/share/applications/${item}', args)) - } - } - println('\n') + buildcategory(args, '/usr/share/applications/', "Utility", "Accessories", mut linkslist) + buildcategory(args, '/usr/share/applications/', "Office", "Office", mut linkslist) + buildcategory(args, '/usr/share/applications/', "Game", "Games", mut linkslist) + buildcategory(args, '/usr/share/applications/', "Graphics", "Graphics", mut linkslist) + buildcategory(args, '/usr/share/applications/', "Network", "Internet", mut linkslist) + buildcategory(args, '/usr/share/applications/', "System", "System Tools", mut linkslist) + buildcategory(args, '/usr/share/applications/', "Other", "NaN", mut linkslist) + + println('') } fn buildprogram(filename string, args []bool) string { @@ -104,7 +98,9 @@ fn buildprogram(filename string, args []bool) string { file := os.read_file(filename) or { panic(err) } + content := file.split_into_lines() + return '${strfinder(content, 2)}' } @@ -153,6 +149,9 @@ fn filter(strorig string, mode int) string { fn checktargetcategory(filename string, check string) bool { //println("checking") + if filename == "NaN" { + return true + } for line in (os.read_file("/usr/share/applications/${filename}") or { panic(err) }).split_into_lines() { if line.contains(check) && line.contains("Categories=") { return true } }